Answer the question
In order to leave comments, you need to log in
How to get date sorted distinct by foreignkey?
In [102]: Episode.objects.order_by('-date_modified').filter(series__series_type='series').values_list('series_id', flat=True).distinct()
Out[102]: [71L, 181L, 181L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 411L, 401L, 401L, 401L, '...(remaining elements truncated)...']
Answer the question
In order to leave comments, you need to log in
This is how I got a list of unique ids sorted by date.
list(Episode.objects.values_list(
'series_id', flat=True
).filter(
series__series_type='series'
).annotate(
Max("date_modified")
).order_by(
'-date_modified__max'
))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question