Hi Everyone i trying to count active and inactive status sepratally, below mention code to count all, i need to count active and inactive status sepratally,pls help me out. pls refere sample data
Type.objects.all().aggregate(Count('status'))
output=5
CodePudding user response:
Look at https://pythonguides.com/python-django-group-by/
Type.objects.values('status').annotate(
status_count=Count('id')
).values(
'status', 'status_count'
).order_by()
EDIT: count only in active status
Type.objects.filter(status='active').aggregate(
active_count=Count('status')
).values('active_count')