django count filter code example
Example 1: django group by
from django.db.models import Count
Members.objects.values('designation').annotate(dcount=Count('designation'))
SELECT designation, COUNT(designation) AS dcount
FROM members GROUP BY designation
[{'designation': 'Salesman', 'dcount': 2},
{'designation': 'Manager', 'dcount': 2}]
Example 2: django filter values with OR operator
Blog.objects.filter(pk__in=[1, 4, 7])
Example 3: django queryset count
Entry.objects.count()
Entry.objects.filter(headline__contains='Lennon').count()