From 43e9ac4625c3b2d4232b02cac6b5224fce485476 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 21 Feb 2018 16:05:35 +0300 Subject: [PATCH] LIL-271. Add balance sum func & show in user menu for author & admin --- apps/user/models.py | 3 +++ project/templates/lilcity/index.html | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/user/models.py b/apps/user/models.py index db34018e..6f18d9e8 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -61,6 +61,9 @@ class User(AbstractUser): user_data = dumps(user_data, ensure_ascii=False) return user_data + def balance(self): + return self.balances.aggregate(models.Sum('amount')).get('amount__sum', 0) + @receiver(post_save, sender=User) def create_auth_token(sender, instance=None, created=False, **kwargs): diff --git a/project/templates/lilcity/index.html b/project/templates/lilcity/index.html index d9adc061..1ae53983 100644 --- a/project/templates/lilcity/index.html +++ b/project/templates/lilcity/index.html @@ -136,9 +136,9 @@
{% endif %}
- {% comment %} 234.120.345 руб. {% endcomment %} - {% if request.user.auth_token %} {% if request.user.role == 1 or request.user.role == 2 %} + {{ request.user.balance }} руб. + {% if request.user.auth_token %} {% comment %} {% endcomment %}
ДОБАВИТЬ КУРС