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

TP9 terminé

parent bb30f917
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,9 @@ class Ingredient(models.Model): ...@@ -8,6 +8,9 @@ class Ingredient(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
nom = models.CharField(max_length=50, verbose_name="Nom de l'ingrédient") nom = models.CharField(max_length=50, verbose_name="Nom de l'ingrédient")
def __str__(self):
return self.nom
def __str__(self) -> str: def __str__(self) -> str:
return self.nom return self.nom
......
...@@ -31,14 +31,16 @@ ...@@ -31,14 +31,16 @@
<tr> <tr>
<th>Ingredient</th> <th>Ingredient</th>
<th>Quantité</th> <th>Quantité</th>
<th>Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for composition in pizza.composition %} {% for composition in pizza.composition %}
<tr> <tr>
{% for field in composition %} <td>{{ composition.1 }}</td>
<td>{{ field }}</td> <td>{{ composition.2 }}</td>
{% endfor %} <td><a href="/pizza/{{ pizza.id }}/deleteIngredient/{{ composition.0 }}" class="btn danger">Supprimer
<i class="icon-trash"></i></a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
...@@ -71,8 +73,9 @@ ...@@ -71,8 +73,9 @@
<div class="actions"> <div class="actions">
<input type="submit" value="Ajouter" class="btn success"> <input type="submit" value="Ajouter" class="btn success">
<button type="reset" class="btn">Annuler</button> <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 }}/update" class="btn info"><i class="icon-pencil"></i> Modifier la
<a href="/pizza/{{ pizza.id }}/delete" class="btn danger">Supprimer la pizza</a> pizza</a>
<a href="/pizza/{{ pizza.id }}/delete" class="btn danger"><i class="icon-trash"></i> Supprimer la pizza</a>
</div> </div>
</form> </form>
</div> </div>
......
...@@ -105,7 +105,7 @@ def viewPizza(request, id, status=None): ...@@ -105,7 +105,7 @@ def viewPizza(request, id, status=None):
composition = Composition.objects.filter(pizza_id=id) composition = Composition.objects.filter(pizza_id=id)
compositionArray = [] compositionArray = []
for c in composition: 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 pizza.composition = compositionArray
if status==None: if status==None:
...@@ -120,3 +120,8 @@ def viewPizza(request, id, status=None): ...@@ -120,3 +120,8 @@ def viewPizza(request, id, status=None):
'applipizza/pizza.html', 'applipizza/pizza.html',
{"pizza": pizza, 'form': formulaire, 'status': status} {"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 = [ ...@@ -26,6 +26,7 @@ urlpatterns = [
path('pizzas/', views.pizzas), path('pizzas/', views.pizzas),
path('pizza/<int:id>', views.pizza), path('pizza/<int:id>', views.pizza),
path('pizza/<int:id>/addIngredient', views.ajouterIngredientDansPizza), 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', views.modifierPizza),
path('pizza/<int:id>/update/post', views.traitementFormulaireModificationPizza), path('pizza/<int:id>/update/post', views.traitementFormulaireModificationPizza),
path('pizza/<int:id>/delete', views.supprimerPizza), 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