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

Création du formulaire de création d'ingrédient.

parent a955f3a9
No related branches found
No related tags found
No related merge requests found
from django.forms import ModelForm
from applipizza.models import Ingredient
class IngredientForm(ModelForm):
class Meta:
model = Ingredient
fields = ['nom']
\ No newline at end of file
{% extends 'applipizza/base.html' %}
{% load static %}
{% block title %}
Lasri Del Arte - Ajouter un ingrédient
{% endblock %}
{% block content %}
<div class="container">
<h2>Ajouter un ingrédient</h2>
<p>Renseigner le nom de l'ingrédient à ajouter.</p>
<form action="" method="post" class="form-stacked">
{% csrf_token %}
{% for field in form %}
{% if field.errors %}
<div class="clearfix error">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="input">
{{ field }}
<span class="help-inline">
{% for error in field.errors %}
{{ error }}
{% endfor %}
</span>
</div>
{% else %}
<div class="clearfix">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="input">
{{ field }}
</div>
</div>
{% endif %}
{% endfor %}
<div class="actions">
<input type="submit" value="Ajouter" class="btn primary">
<button type="reset" class="btn">Annuler</button>
</div>
</form>
</div>
{% endblock %}
{% block javascripts %}
<script type="text/javascript">
var form = $('form');
var formRequiredFields = form.find('input[required]');
var formSubmitButton = form.find('input[type=submit]');
// We disable form validation
form.attr('novalidate', 'novalidate');
form.submit(function (e) {
formRequiredFields.each(function () {
if ($(this).val() == '') {
console.log('empty');
e.preventDefault();
$(this).parent().append('<span class="help-inline">Ce champ est obligatoire</span>');
$(this).parent().parent().addClass('error');
} else {
if ($(this).parent().find('span.help-inline').length > 0) {
$(this).parent().find('span.help-inline').remove();
$(this).parent().parent().removeClass('error');
}
}
});
});
// We disable the submit button
//formSubmitButton.attr('disabled', 'disabled');
</script>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render
from applipizza.models import Pizza, Ingredient, Composition
from applipizza.forms import IngredientForm
# Create your views here.
def pizzas(request):
......@@ -25,3 +25,13 @@ def pizza(request, id):
'applipizza/pizza.html',
{'pizza': pizza}
)
def formulaireCreationIngredient(request):
formulaire = IngredientForm()
return render(
request,
'applipizza/formulaireCreationIngredient.html',
{"form": formulaire}
)
......@@ -21,5 +21,6 @@ from applipizza import views
urlpatterns = [
path('admin/', admin.site.urls),
path('pizzas/', views.pizzas),
path('pizza/<int:id>', views.pizza)
path('pizza/<int:id>', views.pizza),
path('ingredients/add', views.formulaireCreationIngredient)
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment