A
Size: a a a
A
A
AO
AO
AO
AO
AO
AO
AO
AO
AO
AO
A
A
AO
AO
AO
AO
AO
CS
"statistic" : {can some one help
"2016" : [ {1 : 200}, {2 : 400}, ........ {12 : 700}],
"2017" : [ {1 : 200}, {2 : 400}, ........ {12 : 700}],
}
def last_day_of_month(self, any_day):
next_month = any_day.replace(day=28) + datetime.timedelta(days=4) # this will never fail
return next_month - datetime.timedelta(days=next_month.day)
def get_messages_years(self, obj):
qs = obj.envelopemodel_set
years = qs.dates("date", "year").distinct()
data = dict()
for y in years:
month_ = dict()
for month in range(1, 13):
count = qs.filter(
date__range=(datetime.datetime(y.year, month, 1, tzinfo=timezone.utc),
self.last_day_of_month(
datetime.datetime(y.year, month, 1, tzinfo=timezone.utc)))).count()
month_[month] = count
data[y.year] = month_
return data