Commit aae44beb authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch '278-commissielid-sinds-negeert-voorgaande-lidmaatschappen' into 'master'

Display correct initial join date for consecutive committee memberships

Closes #278

See merge request !313
parents 39e94fc4 6513ef7a
...@@ -177,6 +177,17 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta): ...@@ -177,6 +177,17 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
null=True, null=True,
) )
def initial_connected_membership(self):
""" Find the oldest membership directly connected to the current one"""
qs = CommitteeMembership.objects.filter(committee=self.committee,
if qs.count() >= 1: # should actually only be one; should be unique
return qs.first().initial_connected_membership
return self
@property @property
def is_active(self): def is_active(self):
"""Is this membership currently active""" """Is this membership currently active"""
...@@ -22,13 +22,15 @@ def committee_detail(request, id): ...@@ -22,13 +22,15 @@ def committee_detail(request, id):
memberships = (CommitteeMembership memberships = (CommitteeMembership
.active_memberships .active_memberships
.filter(committee=committee) .filter(committee=committee)
.prefetch_related('member')) .prefetch_related('member__committeemembership_set'))
for membership in memberships: for membership in memberships:
member = membership.member member = membership.member
member.chair = membership.chair member.chair = membership.chair
member.committee_since = membership.since member.committee_since = membership.initial_connected_membership.since
members.append(member) # list comprehension would be more pythonic? members.append(member) # list comprehension would be more pythonic?
members.sort(key=lambda x: x.committee_since)
return render(request, 'activemembers/committee_detail.html', return render(request, 'activemembers/committee_detail.html',
{'committee': committee, {'committee': committee,
'members': members}) 'members': members})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment