Better format for quantite

This commit is contained in:
Claude Paroz 2018-05-27 16:01:08 +02:00
parent 4f48503ab1
commit 491b7a33cf
2 changed files with 10 additions and 2 deletions

View file

@ -53,7 +53,15 @@ class Composition(models.Model):
unite = models.ForeignKey(Unite, null=True, blank=True, on_delete=models.PROTECT)
def __str__(self):
return "%s %s %s" % (self.quantite, self.unite.nom, self.ingredient.nom)
return "%s %s %s" % (
self.quantite_formatted or '', self.unite.nom if self.unite else '', self.ingredient.nom
)
@property
def quantite_formatted(self):
if self.quantite is None:
return ''
return str(self.quantite).rstrip('0').rstrip('.')
@receiver(models.signals.post_delete, sender=Recette)

View file

@ -9,7 +9,7 @@
<div class="ingredients">
<h2>Ingrédients</h2>
<ul>
{% for comp in recette.ingredients.all %}
{% for comp in recette.composition_set.all %}
<li>{{ comp }}</li>
{% endfor %}
</ul>