Allow ingredient editing in admin

This commit is contained in:
Claude Paroz 2018-05-27 11:48:40 +02:00
parent c369fbac1e
commit 1247a53278
2 changed files with 9 additions and 1 deletions

View file

@ -4,6 +4,10 @@ from django.contrib import admin
from .models import Composition, Ingredient, Recette, Unite from .models import Composition, Ingredient, Recette, Unite
class IngredientInline(admin.TabularInline):
model = Recette.ingredients.through
class RecetteForm(forms.ModelForm): class RecetteForm(forms.ModelForm):
photo = forms.ImageField( photo = forms.ImageField(
label="Photo", label="Photo",
@ -18,6 +22,7 @@ class RecetteForm(forms.ModelForm):
@admin.register(Recette) @admin.register(Recette)
class RecetteAdmin(admin.ModelAdmin): class RecetteAdmin(admin.ModelAdmin):
form = RecetteForm form = RecetteForm
inlines = [IngredientInline]
admin.site.register(Composition) admin.site.register(Composition)

View file

@ -3,11 +3,14 @@
{% block content %} {% block content %}
<h1>{{ recette.nom }}</h1> <h1>{{ recette.nom }}</h1>
{% if recette.photo %}
<div class="photo"><img src="{{ recette.photo.url }}"></div> <div class="photo"><img src="{{ recette.photo.url }}"></div>
{% endif %}
<div>{{ recette.preparation }}</div> <div>{{ recette.prep|linebreaksbr }}</div>
{% if recette.ingredients.count %} {% if recette.ingredients.count %}
<h2>Ingrédients</h2>
<ul> <ul>
{% for comp in recette.ingredients.all %} {% for comp in recette.ingredients.all %}
<li>{{ comp }}</li> <li>{{ comp }}</li>