Skip to content
Extraits de code Groupes Projets
Valider bbb11560 rédigé par Nicolas Joyard's avatar Nicolas Joyard
Parcourir les fichiers

Add Chamber model

parent 78d00375
Branches
Étiquettes
Aucune requête de fusion associée trouvée
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('representatives', '0013_constituency_country_related_name'),
]
operations = [
migrations.CreateModel(
name='Chamber',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('fingerprint', models.CharField(unique=True, max_length=40)),
('name', models.CharField(max_length=255)),
('country', models.ForeignKey(related_name='chambers', blank=True, to='representatives.Country', null=True)),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='group',
name='chamber',
field=models.ForeignKey(related_name='groups', to='representatives.Chamber', null=True),
),
]
......@@ -41,9 +41,11 @@ class HashableModel(models.Model):
for field_name in self.hashable_fields:
field = self._meta.get_field(field_name)
if field.is_relation:
fingerprint.update(
getattr(self, field_name).fingerprint
)
related = getattr(self, field_name)
if related is None:
fingerprint.update(smart_str(related))
else:
fingerprint.update(related.fingerprint)
else:
fingerprint.update(
smart_str(getattr(self, field_name))
......@@ -162,6 +164,16 @@ class Phone(Contact):
address = models.ForeignKey(Address, null=True, related_name='phones')
class Chamber(HashableModel):
"""
A representative chamber
"""
name = models.CharField(max_length=255)
country = models.ForeignKey('Country', null=True, related_name='chambers')
hashable_fields = ['name', 'country']
class Group(HashableModel, TimeStampedModel):
"""
An entity represented by a representative through a mandate
......@@ -170,8 +182,9 @@ class Group(HashableModel, TimeStampedModel):
abbreviation = models.CharField(max_length=10, blank=True, default='',
db_index=True)
kind = models.CharField(max_length=255, db_index=True)
chamber = models.ForeignKey(Chamber, null=True, related_name='groups')
hashable_fields = ['name', 'abbreviation', 'kind']
hashable_fields = ['name', 'abbreviation', 'kind', 'chamber']
@cached_property
def active(self):
......@@ -234,8 +247,8 @@ class Mandate(HashableModel, TimeStampedModel):
end_date = models.DateField(blank=True, null=True)
link = models.URLField()
hashable_fields = ['group', 'constituency', 'role',
'begin_date', 'end_date', 'representative']
hashable_fields = ['group', 'constituency', 'role', 'begin_date',
'end_date', 'representative']
@property
def active(self):
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter