Skip to content

Commit

Permalink
fix: incorrect statistics in organisation admin list (#4546)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell authored Aug 29, 2024
1 parent 55fc88d commit bc3ddaf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions api/organisations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals

from django.contrib import admin
from django.db.models import Count
from django.db.models import Count, Q

from organisations.models import Organisation, Subscription, UserOrganisation
from projects.models import Project
Expand Down Expand Up @@ -49,12 +49,18 @@ class OrganisationAdmin(admin.ModelAdmin):
list_filter = ("subscription__plan",)
search_fields = ("id", "name", "subscription__subscription_id", "users__email")

def get_queryset(self, request):
def get_queryset(self, request): # pragma: no cover
return (
Organisation.objects.select_related("subscription")
.annotate(
num_users=Count("users", distinct=True),
num_projects=Count("projects", distinct=True),
num_users=Count(
"users", distinct=True, filter=Q(users__is_active=True)
),
num_projects=Count(
"projects",
distinct=True,
filter=Q(projects__deleted_at__isnull=True),
),
)
.all()
)
Expand Down

0 comments on commit bc3ddaf

Please sign in to comment.