Reputation: 4313
I have model like this:
class A(models.Model):
done = models.Boolean()
And want to check if all done
are True
:
A.objects.count() == A.objects.filter(done=True).count()
But how to do the same thing inside DB in one query?
???
A.objects.annotate(Count('done??')).aggregate(??)
???
Upvotes: 1
Views: 148
Reputation: 599610
You should filter on done=False and check if there are any results with exists
.
A.objects.filter(done=False).exists()
Upvotes: 4