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):