Have got name ‘Count’ is not defined when doing annotate query in Django?


When you got “NameError: name ‘Count’ is not defined” when doing annotate query. Remember to import Count from django.db.models.

1
2
3
from django.db.models import Count

q = Insurance.objects.annotate(Count(‘created’))

Somehow it’s missing in the Django documentation 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.