Issue
This is bound to be a duplicate question but I can't find any others. I'm trying to get a list of photos that have complaints. I can't simply get complaints and deal with the related photos - I need a queryset of photos.
This should work but doesn't seem right:
Photo.objects.filter(complaint__id__gte=0)
This doesn't seem like the most efficient way:
Photo.objects.annotate(Count('complaint')).exclude(complaint__count=0)
Is there a better way?
Solution
how about ...
Photo.objects.filter(complaint__isnull=False)
from https://docs.djangoproject.com/en/dev/topics/db/queries/
Answered By - jcfollower
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.