2👍
Try using:
MyModel.objects.filter('some filter').values_list("id).count()
This will do this query:
select count(id) from MyModel
1👍
Try using an aggregate query:
from django.db import models
MyObject.objects.all().aggregate(models.Count('id'))['id__count']
- [Django]-Django-social auth KeyError
- [Django]-Is anyone implemented django celery worker as docker container it only runs when task assigned
- [Django]-Product variants not reflecting updated quantity in Order Summary in a Django E-commerce Project
- [Django]-Name Error: global name 'loader' is not defined
- [Django]-How to set required fields in PATCH API in Swagger UI
0👍
COUNT(id)
is roughly the equivalent of:
MyModel.objects.exclude(id=None).count()
this will add extra step to count the table fields, which is not the case for COUNT(*)
- [Django]-Django Validators in Serializer vs Constraints in Models
- [Django]-How to make easy_install expand a package into directories rather than a single egg file?
- [Django]-'ImageFieldFile' object has no attribute 'content_type' only after picture has already been uploaded then isn't either changed or removed
- [Django]-Django-http-proxy prepending slash
Source:stackexchange.com