'how Count field using django orm

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 

table formet



Solution 1:[1]

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')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1