Use OccupationSerializer for the Contacts API
This commit is contained in:
+3
-7
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user