<commit_before>from django.db import models
from django.contrib.auth.models import User
from denorm.fields import denormalized
from denorm.dependencies import BackwardForeignKey,ForwardForeignKey


class Picture(models.Model):
    name = models.CharField(max_length=100)
    owner = models.ForeignKey(User)
    image = models.ImageField(upload_to='photos')
    gallery = models.ForeignKey('Gallery')

    def __unicode__(self):
        return self.name


class Gallery(models.Model):
    name = models.CharField(max_length=100)

    @denormalized(models.TextField,blank=True,depend=BackwardForeignKey(Picture))
    def users(self):
        return ', '.join(str(p.owner) for p in self.picture_set.all())

    def __unicode__(self):
        return self.name

class Comment(models.Model):
    text = models.TextField()
    picture = models.ForeignKey(Picture)

    @denormalized(models.CharField,max_length=100,depend=ForwardForeignKey(Picture))
    def picture_name(self):
        return self.picture.name

    def __unicode__(self):
        return u'Comment on %s' % (self.picture_name)
<commit_msg>fixed problem in example when username in User model changes<commit_after>from django.db import models
from django.contrib.auth.models import User
from denorm.fields import denormalized
from denorm.dependencies import BackwardForeignKey,ForwardForeignKey


class Picture(models.Model):
    name = models.CharField(max_length=100)
    owner = models.ForeignKey(User)
    image = models.ImageField(upload_to='photos')
    gallery = models.ForeignKey('Gallery')

    @denormalized(models.CharField,max_length=100,depend=ForwardForeignKey(User))
    def owner_username(self):
        return self.owner.username

    def __unicode__(self):
        return self.name


class Gallery(models.Model):
    name = models.CharField(max_length=100)

    @denormalized(models.TextField,blank=True,depend=BackwardForeignKey(Picture))
    def users(self):
        return ', '.join(p.owner_username for p in self.picture_set.all())

    def __unicode__(self):
        return self.name

class Comment(models.Model):
    text = models.TextField()
    picture = models.ForeignKey(Picture)

    @denormalized(models.CharField,max_length=100,depend=ForwardForeignKey(Picture))
    def picture_name(self):
        return self.picture.name

    def __unicode__(self):
        return u'Comment on %s' % (self.picture_name)

{'fraction_non_alphanumeric': 0.1022964509394572, 'fraction_numerical': 0.008768267223382045, 'mean_word_length': 4.33630289532294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4194834', 'n_tokens_mistral': 731, 'n_tokens_neox': 685, 'n_words': 144}