PetitCoursAttributionCounter defaults to 0

This commit is contained in:
Martin Pépin 2017-10-25 22:01:58 +02:00
parent 8e8e9aa076
commit a07b5308a3

View file

@ -157,14 +157,16 @@ class PetitCoursAttributionCounter(models.Model):
compteurs de tout le monde.
"""
counter, created = cls.objects.get_or_create(
user=user, matiere=matiere)
user=user,
matiere=matiere,
)
if created:
mincount = (
cls.objects.filter(matiere=matiere).exclude(user=user)
.aggregate(Min('count'))
['count__min']
)
counter.count = mincount
counter.count = mincount or 0
counter.save()
return counter