select_related django filter code example
Example 1: django filter on related field
len(Collection.objects.filter(item__flag=True).distinct())
Example 2: django select_related and prefetch_related
django select_related and prefetch_related
select_related >> foreignkey
prefetch_related >> many to many
basically they are performance boosters ,used to avoid multiple unnecessary queries
Both methods achieve the same purpose, to forego unnecessary db queries.
But they use different approaches for efficiency..