Commit 0bfc5643 authored by Tom van Bussel's avatar Tom van Bussel
Browse files

no longer count members twice in statistics

Members with multiple `Membership` objects were counted twice in the statistics.
If a Member has multiple `Membership` objects and a queryset filters on
`user__membership` the Member will appear multiple times in the result, by doing
a `.distinct()` these duplicates are removed.
parent 8f57d9b8
......@@ -24,7 +24,8 @@ class ActiveMemberManager(models.Manager):
return (super().get_queryset()
.exclude(user__membership=None)
.filter(Q(user__membership__until__isnull=True) |
Q(user__membership__until__gt=timezone.now().date())))
Q(user__membership__until__gt=timezone.now().date()))
.distinct())
def with_birthdays_in_range(self, from_date, to_date):
queryset = self.get_queryset().filter(birthday__lte=to_date)
......@@ -440,6 +441,7 @@ def gen_stats_member_type(member_types):
total[member_type] = (Member
.active_members
.filter(user__membership__type=member_type)
.distinct()
.count())
return total
......@@ -460,6 +462,7 @@ def gen_stats_year(member_types):
.active_members
.filter(starting_year=current_year - i)
.filter(user__membership__type=member_type)
.distinct()
.count())
stats_year.append(new)
......@@ -470,6 +473,7 @@ def gen_stats_year(member_types):
.active_members
.filter(starting_year__lt=current_year - 4)
.filter(user__membership__type=member_type)
.distinct()
.count())
stats_year.append(new)
......
Markdown is supported
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