jazzband / django-taggit

Simple tagging for django
https://django-taggit.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.34k stars 622 forks source link

Documentation - Add example for reverse filtering #789

Open chgad opened 2 years ago

chgad commented 2 years ago

I came across the case where I wanted to query all Tags which have a certain property set on the related model like:

>>>Tag.objects.filter(food__is_vegetarian=True)
[<Tag: salad>, <Tag: salad>, <Tag: fruit>, <Tag: fruit>]

which can be easily solved by the given example for the Food query here by adding the .distinct() call.

Once you think about it, it is obvious but maybe we can just add it to be more explicit on this regard.