add percentage property method

This commit is contained in:
Fred 2015-12-08 21:21:45 +01:00
parent 683729be29
commit ec89d25b36
1 changed files with 9 additions and 0 deletions

View File

@ -44,6 +44,15 @@ class Wish(models.Model):
i.save()
return i
@property
def percentage(self):
"""
Calcule le pourcentage de complétion pour un élément.
"""
number_of_linked_parts = Part.objects.filter(wish=self).count()
total = self.number_of_parts * self.numbers_available
percentage = (number_of_linked_parts / total)
return percentage * 100
class Part(models.Model):
wish = models.ForeignKey('Wish')