I need to construct a query in Django, and I'm wondering if this is somehow possible (it may be really obvious but I'm missing it...).
I have a normal query Model.objects.filter(x=True)[:5]
which can return results like this:
FirstName LastName Country Bob Jones UK Bill Thompson UK David Smith USA
I need to only grab rows which are distinct based on the Country
field, something like Model.objects.filter(x=True).distinct('Country')[:5]
would be ideal but that's not possible with Django.
The rows I want the query to grab ultimately are:
FirstName LastName Country Bob Jones UK David Smith USA
I also need the query to use the same ordering as set in the model's Meta class (ie. I can't override the ordering in any way).
How would I go about doing this?
Thanks a lot.