<commit_before>from django.db import models

class RepsContainerManager(models.Manager):
    """ Manager for models to which the REP model has a foreign key"""
    def with_counts(self):
        """ Return the models with a count property, with the count of active Reps """
        return self.get_query_set().filter(rep__active=True).annotate(count=models.Count('rep'))


class Party(models.Model):
    name = models.CharField(max_length=255, unique=True)

    objects = RepsContainerManager()

    def __unicode__(self):
        return self.name

    @property
    def reps(self):
        return self.mep_set.filter(active=True)

class Opinion(models.Model):
    title = models.CharField(max_length=255, unique=True)
    content = models.TextField()
    url = models.URLField()

    def __unicode__(self):
        return self.title

class Representative(models.Model):
    id = models.CharField(max_length=255, primary_key=True)
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    full_name = models.CharField(max_length=255, null=True)
    gender = models.CharField(max_length=2, choices=((u'M', u'Male'), (u'F', u'Female')))
    picture = models.CharField(max_length=255, unique=True)
    #picture = models.ImageField(upload_to="")
    birth_date = models.DateField()
    birth_place = models.CharField(max_length=255)
    local_party = models.ManyToManyField(Party, through='PartyRepresentative')
    opinions = models.ManyToManyField(Opinion, through='OpinionREP')

    def __unicode__(self):
        return self.full_name

    class Meta:
        ordering = ['last_name']

class PartyRepresentative(models.Model):
    representative = models.ForeignKey(Representative)
    party = models.ForeignKey(Party)
    role = models.CharField(max_length=255)
    current = models.BooleanField()
    # well maybe need those one day
    #begin = models.DateField()
    #end = models.DateField()

class Email(models.Model):
    email = models.EmailField()
    rep = models.ForeignKey(Representative)

    def __unicode__(self):
        return self.email

class CV(models.Model):
    title = models.CharField(max_length=1023)
    rep = models.ForeignKey(Representative)

    def __unicode__(self):
        return self.title

class WebSite(models.Model):
    url = models.URLField()
    rep = models.ForeignKey(Representative)

    def __unicode__(self):
        return self.url


class OpinionREP(models.Model):
    rep = models.ForeignKey(Representative)
    opinion = models.ForeignKey(Opinion)
    date = models.DateField()

    def __unicode__(self):
        return u"%s : %s" % (self.opinion, self.mep)
<commit_msg>[fix] unify foreignkey from rep to representative<commit_after>from django.db import models

class RepsContainerManager(models.Manager):
    """ Manager for models to which the representative model has a foreign key"""
    def with_counts(self):
        """ Return the models with a count property, with the count of active Reps """
        return self.get_query_set().filter(representative__active=True).annotate(count=models.Count('representative'))


class Party(models.Model):
    name = models.CharField(max_length=255, unique=True)

    objects = RepsContainerManager()

    def __unicode__(self):
        return self.name

    @property
    def reps(self):
        return self.mep_set.filter(active=True)

class Opinion(models.Model):
    title = models.CharField(max_length=255, unique=True)
    content = models.TextField()
    url = models.URLField()

    def __unicode__(self):
        return self.title

class Representative(models.Model):
    id = models.CharField(max_length=255, primary_key=True)
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    full_name = models.CharField(max_length=255, null=True)
    gender = models.CharField(max_length=2, choices=((u'M', u'Male'), (u'F', u'Female')))
    picture = models.CharField(max_length=255, unique=True)
    #picture = models.ImageField(upload_to="")
    birth_date = models.DateField()
    birth_place = models.CharField(max_length=255)
    local_party = models.ManyToManyField(Party, through='PartyRepresentative')
    opinions = models.ManyToManyField(Opinion, through='OpinionREP')

    def __unicode__(self):
        return self.full_name

    class Meta:
        ordering = ['last_name']

class PartyRepresentative(models.Model):
    representative = models.ForeignKey(Representative)
    party = models.ForeignKey(Party)
    role = models.CharField(max_length=255)
    current = models.BooleanField()
    # well maybe need those one day
    #begin = models.DateField()
    #end = models.DateField()

class Email(models.Model):
    email = models.EmailField()
    representative = models.ForeignKey(Representative)

    def __unicode__(self):
        return self.email

class CV(models.Model):
    title = models.CharField(max_length=1023)
    representative = models.ForeignKey(Representative)

    def __unicode__(self):
        return self.title

class WebSite(models.Model):
    url = models.URLField()
    representative = models.ForeignKey(Representative)

    def __unicode__(self):
        return self.url


class OpinionREP(models.Model):
    representative = models.ForeignKey(Representative)
    opinion = models.ForeignKey(Opinion)
    date = models.DateField()

    def __unicode__(self):
        return u"%s : %s" % (self.opinion, self.mep)

{'fraction_non_alphanumeric': 0.11170310490538306, 'fraction_numerical': 0.011758221568987691, 'mean_word_length': 3.9445958219800183, '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': '3666130', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1610, 'n_words': 346}