How to obtain months in right order from different years from DateField in django? -
i have django model datefield. can list of months of objects in such way:
months = [i.month in mymodel.objects.values_list('date', flat=true)]
and after delete duplicates receive such list (example): [1, 2, 5, 6, 7, 9]
.
but if have different years, want receive months in right date order. example:
date1=31.08.2012, date2=31.12.2012, date3=05.05.2013.
so want receive not [5, 8, 12
] [8, 12, 5]
.
how can it?
you're trying months in order of when first appear chronologically?
list(set(date.month date in mymodel.objects.order_by("date").values_list('date', flat=true)))
sorting year same sorting date. yay!
Comments
Post a Comment