Skip to content
Snippets Groups Projects
Commit e65da1d9 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

TP9 terminé

parent bb30f917
Branches
No related tags found
No related merge requests found
......@@ -8,6 +8,9 @@ class Ingredient(models.Model):
id = models.AutoField(primary_key=True)
nom = models.CharField(max_length=50, verbose_name="Nom de l'ingrédient")
def __str__(self):
return self.nom
def __str__(self) -> str:
return self.nom
......
......@@ -31,14 +31,16 @@
<tr>
<th>Ingredient</th>
<th>Quantité</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for composition in pizza.composition %}
<tr>
{% for field in composition %}
<td>{{ field }}</td>
{% endfor %}
<td>{{ composition.1 }}</td>
<td>{{ composition.2 }}</td>
<td><a href="/pizza/{{ pizza.id }}/deleteIngredient/{{ composition.0 }}" class="btn danger">Supprimer
<i class="icon-trash"></i></a></td>
</tr>
{% endfor %}
</tbody>
......@@ -71,8 +73,9 @@
<div class="actions">
<input type="submit" value="Ajouter" class="btn success">
<button type="reset" class="btn">Annuler</button>
<a href="/pizza/{{ pizza.id }}/update" class="btn info">Modifier la pizza</a>
<a href="/pizza/{{ pizza.id }}/delete" class="btn danger">Supprimer la pizza</a>
<a href="/pizza/{{ pizza.id }}/update" class="btn info"><i class="icon-pencil"></i> Modifier la
pizza</a>
<a href="/pizza/{{ pizza.id }}/delete" class="btn danger"><i class="icon-trash"></i> Supprimer la pizza</a>
</div>
</form>
</div>
......
......@@ -105,7 +105,7 @@ def viewPizza(request, id, status=None):
composition = Composition.objects.filter(pizza_id=id)
compositionArray = []
for c in composition:
compositionArray.append([Ingredient.objects.get(id=c.ingredient_id).nom, c.quantite])
compositionArray.append([c.id, Ingredient.objects.get(id=c.ingredient_id).nom, c.quantite])
pizza.composition = compositionArray
if status==None:
......@@ -120,3 +120,8 @@ def viewPizza(request, id, status=None):
'applipizza/pizza.html',
{"pizza": pizza, 'form': formulaire, 'status': status}
)
def supprimerIngredientDansPizza(request, pizzaId, compositionId):
composition = Composition.objects.get(id=compositionId)
composition.delete()
return viewPizza(request, pizzaId, 'success')
\ No newline at end of file
......@@ -26,6 +26,7 @@ urlpatterns = [
path('pizzas/', views.pizzas),
path('pizza/<int:id>', views.pizza),
path('pizza/<int:id>/addIngredient', views.ajouterIngredientDansPizza),
path('pizza/<int:pizzaId>/deleteIngredient/<int:compositionId>', views.supprimerIngredientDansPizza),
path('pizza/<int:id>/update', views.modifierPizza),
path('pizza/<int:id>/update/post', views.traitementFormulaireModificationPizza),
path('pizza/<int:id>/delete', views.supprimerPizza),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment