From f9cea668041c0050b9d841b4cd9dd12df80b8464 Mon Sep 17 00:00:00 2001 From: Nanoy Date: Mon, 25 Feb 2019 11:13:42 +0100 Subject: [PATCH] =?UTF-8?q?R=C3=A9solution=20du=20probl=C3=A8me=20de=20Fou?= =?UTF-8?q?lques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gestion/models.py b/gestion/models.py index 9921418..e608ff5 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -47,12 +47,11 @@ class Product(models.Model): def user_ranking(self, pk): user = User.objects.get(pk=pk) - consumptions = ConsumptionHistory.objects.filter(customer=user).filter(product=self) - # add menu - nb = 0 - for consumption in consumptions: - nb += consumption.quantity - return (user, nb) + consumptions = Consumption.objects.filter(customer=user).filter(product=self) + if consumptions: + return (user, consumptions[0].quantity) + else: + return (user, 0) @property def ranking(self):