django select_related code example
Example 1: django order by
class Meta:
ordering = ('date',)
Example 2: django filter exsist
if table.objects.filter(prop='value').count() > 0:
Example 3: 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..