Better format for quantite
This commit is contained in:
parent
4f48503ab1
commit
491b7a33cf
|
@ -53,7 +53,15 @@ class Composition(models.Model):
|
||||||
unite = models.ForeignKey(Unite, null=True, blank=True, on_delete=models.PROTECT)
|
unite = models.ForeignKey(Unite, null=True, blank=True, on_delete=models.PROTECT)
|
||||||
|
|
||||||
def __str__(self):
|
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)
|
@receiver(models.signals.post_delete, sender=Recette)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="ingredients">
|
<div class="ingredients">
|
||||||
<h2>Ingrédients</h2>
|
<h2>Ingrédients</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for comp in recette.ingredients.all %}
|
{% for comp in recette.composition_set.all %}
|
||||||
<li>{{ comp }}</li>
|
<li>{{ comp }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue