.distinct()
is the tool, but here’s the syntax I had to use :
Model.objects.values_list('name', flat=True).distinct()
This way you only get a list [A,B,C,D] of values, not the objects themseleves.
Pek zarif olmasada aşağıdaki de kullanılır.
# Fetch all rows to limit num of queries
all_rows = MyModel.objects.all()
# Query against the full list to return a list of objects
item_list = [all_rows.filter(myfield=item['myfield']).last() for item in MyModel.objects.values('myfield').distinct()]