From b6af65e9158ad4ff44cf9cfa5d8239a049ca3f19 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 5 Mar 2023 19:20:07 +0100 Subject: [PATCH] Implement add recipe with version --- recipes/forms.py | 5 ++++ recipes/templates/add-recipe.html | 41 +++++++++++++++++++++++++++++++ recipes/templates/recipes.html | 2 +- recipes/urls.py | 1 + recipes/views.py | 32 ++++++++++++++++++++++-- 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 recipes/templates/add-recipe.html diff --git a/recipes/forms.py b/recipes/forms.py index 95dbac5..f02cf4d 100644 --- a/recipes/forms.py +++ b/recipes/forms.py @@ -1,6 +1,11 @@ from django.forms import ModelForm, ValidationError, modelformset_factory, BooleanField from .models import Recipe, Version, Ingredient +class RecipeForm(ModelForm): + class Meta: + model = Recipe + fields = ['title', 'slug'] + class VersionForm(ModelForm): recipe_id: int diff --git a/recipes/templates/add-recipe.html b/recipes/templates/add-recipe.html new file mode 100644 index 0000000..bd8968c --- /dev/null +++ b/recipes/templates/add-recipe.html @@ -0,0 +1,41 @@ +{% extends "base_main.html" %} +{% block title %}{{ recipe.title }}{% endblock %} +{% block main %} +
+ {%csrf_token %} + {{ recipe_form.as_div }} + + {{ version_form.as_table }} +
+ {{ ingredients_formset.management_form }} + {% for ingredient_form in ingredients_formset %} + {{ ingredient_form.as_div }} + {% endfor %} + + +
+ + + +{% endblock %} diff --git a/recipes/templates/recipes.html b/recipes/templates/recipes.html index a60027c..33273b0 100644 --- a/recipes/templates/recipes.html +++ b/recipes/templates/recipes.html @@ -3,7 +3,7 @@ {% block main %}

Recipes

{% if perms.recipes.add_recipe %} -

Add recipe

+

Add recipe

{% endif %} {% if perms.recipes.view_recipe %}