python - How group by date in Django -
i have 2 dates.
start_date = '2015/01/01'
end_date = '2015/04/01'
query return orders between 2 dates, need group month. so:
data1: 2015/01/01 #start_date
data2: 2015/02/01
data3: 2015/03/01
data4: 2015/04/01 #end_date
i need chart data.
you try itertools.groupby
, careful django might cache generator list , consume it.
from itertools import groupby groupby(orders, lambda order : order.date.month)