django-siteflags
django-siteflags copied to clipboard
Best way to get a queryset with flagged objects of a certain model?
I was hoping to do a quick check here. If I were to populate a queryset with objects of a certain type (in this case Profile), that were flagged a specific flag (in this case FLAG_STAR) by a specific user, would this be the best way to go?
flags_for_types = ModelWithFlag.get_flags_for_types([Profile], user=self.request.user, status=Profile.FLAG_STAR)
qs = Profile.objects.filter(flags__in=flags_for_types[Profile])
You may want to try various approaches to see what plays the best.
For example use db_queries fixture in your tests to see what SQL commands are produced for your approach and compare those to, say, Profile.get_flags()
with selected related linked_object
. Or you may use django-debug-toolbar to see those SQLs and timings right in your browser.