From 8d060af46cda6e72730f83c0bc64b5097e94e5ef Mon Sep 17 00:00:00 2001 From: klmp200 Date: Thu, 8 Sep 2016 03:21:39 +0200 Subject: [PATCH] Removed wierd hack --- core/views/user.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/core/views/user.py b/core/views/user.py index 716a2ffd..dc7674cc 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -327,28 +327,22 @@ class UserAccountView(UserAccountBase): def expense_by_month(self, obj, calc): stats = [] - joined = self.object.date_joined.year - years = datetime.now().year - joined - - years = range(0, years + 1) - months = range(1, 12) - - for y in years: + for year in obj.datetimes('date', 'year', order='ASC'): stats.append([]) - for m in months: + i = 0 + for month in obj.filter(date__year=year.year).datetimes( + 'date', 'month', order='ASC'): q = obj.filter( - date__year=joined + y, - date__month=m, - ) - stats[y].append( - ( - sum([calc(p) for p in q]), - date(joined + y, m, 17) - ) + date__year=month.year, + date__month=month.month ) + stats[i].append(( + sum([calc(p) for p in q]), + month + )) + i += 1 - print(stats) return stats def buyings_calc(self, query):