Use OccupationSerializer for the Contacts API

This commit is contained in:
Aarni Halinen
2019-10-10 18:37:15 +03:00
parent 4b63de6fc4
commit e5cc62bbbf
4 changed files with 34 additions and 21 deletions
+3 -7
View File
@@ -195,7 +195,7 @@ class Occupation(models.Model):
role = models.ForeignKey('Role', on_delete=models.SET_NULL, null=True)
@staticmethod
def occupations_by_year(year):
def by_year(year):
return Occupation.objects.filter(
end_date__gte=timezone.datetime(year, 1, 1)).filter(
start_date__lte=timezone.datetime(year, 12, 31))
@@ -219,14 +219,10 @@ class Official(models.Model):
last_name = models.CharField(_('Last name'), max_length=150)
email = models.EmailField(_('Email address'))
phone_number = PhoneNumberField(_('Phone number'))
role_history = models.ManyToManyField('Occupation', blank=True)
@property
def current_roles(self):
return self.role_history.all().filter(end_date__gte=timezone.now())
role_history = models.ManyToManyField('Occupation', 'officials', blank=True)
@staticmethod
def official_by_year(year):
def by_year(year):
return Official.objects.filter(
role_history__in=Occupation.occupations_by_year(year)).distinct()