Getting distinct records from the database is very common requirement. Here is the django ORM query to get the distinct records in Django.
queryset = ModelClassName.objects.filter(FilterCondition) queryset = queryset.distinct().all()
.filter() returns a queryset which can be further modified. We can apply distinct() clause on queryset.
Result of above ORM query will be equivalent to raw sql query showing below:
select distinct modelClassName.fieldName1, modelClassName.fieldName2 from modelClassName where <>