[Django]-I need to display summary report in Django admin site. How do I count number of users where gender status is 0 or 1

5👍

All you need to do is add a case to both the male and female metrics. Here’s an example, and then you can do the same for female = 0:

from django.db.models import Case, When, IntegerField

class MyHelperGenderAdmin(admin.ModelAdmin):

...

metrics = {
   ...
   'male': Count(Case(
                When(gender = 1, then = 1),
                output_field = IntegerField())),
   ...
   }

Leave a comment