Reputation: 531
I want to get distinct pair of quarter and year but following query is giving duplicate pairs
DataValue.objects.values('period_quarter','period_year').distinct()
output:
[
{
'period_year': '2019',
'period_quarter': 'Q2'
},
{
'period_year': '2019',
'period_quarter': 'Q2'
},
{
'period_year': '2019',
'period_quarter': 'Q2'
}
]
Upvotes: 1
Views: 81
Reputation: 14945
From the Docs:
When you specify field names, you must provide an order_by() in the QuerySet, and the fields in order_by() must start with the fields in distinct(), in the same order.
Try:
DataValue.objects.order_by('period_quarter','period_year').distinct('period_quarter','period_year')
Upvotes: 2