Forums

How to get distinct values from a model

Hi, Is there a way to get distinct values from a model?

Currently, I have:

query = model_name.objects.filter(username = 'Bob').order_by('number')

and get 3, 7, 13, 14, 14.

I would like to not repeat the 14, so I tried:

model_name.objects.filter(username = 'Bob').order_by('number').distinct('number'),

but I get an error message that says

'DISTINCT ON fields is not supported by this database backend'.

Without changing databases, is there a way to get distinct values to show in a queryset?

Thank you!

Sorry, I get 3, 7, 13, 14, 14 by also using query.number after I do the query.

Problem solved.

Glad you figured that out!