Unverified Commit 7f809674 authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

Use first of consecutive committee memberships

This typically resulted in incorrect dates for committee chairs
who had previously been member of the committee as nonchair
parent d18859db
......@@ -177,6 +177,17 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
null=True,
)
@property
def initial_connected_membership(self):
""" Find the oldest membership directly connected to the current one"""
qs = CommitteeMembership.objects.filter(committee=self.committee,
member=self.member,
until=self.since)
if qs.count() >= 1: # should actually only be one; should be unique
return qs.first().initial_connected_membership
else:
return self
@property
def is_active(self):
"""Is this membership currently active"""
......
......@@ -22,11 +22,11 @@ def committee_detail(request, id):
memberships = (CommitteeMembership
.active_memberships
.filter(committee=committee)
.prefetch_related('member'))
.prefetch_related('member__committeemembership_set'))
for membership in memberships:
member = membership.member
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?
return render(request, 'activemembers/committee_detail.html',
......
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