From 9a5a0aa617b86c054f70784ae0b5ccfabb7e7830 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 1 Feb 2018 15:59:59 +0100 Subject: [PATCH] edit start --- .idea/workspace.xml | 68 +++++++++++++++++++++------------------------ cookbook/forms.py | 10 +++---- cookbook/tables.py | 2 +- cookbook/views.py | 14 +++++++++- 4 files changed, 51 insertions(+), 43 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9ea723ede..162cd8933 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,9 @@ + - - - - - @@ -210,7 +206,7 @@ - + @@ -280,7 +276,7 @@ - + @@ -596,16 +592,6 @@ - - - - - - - - - - @@ -624,16 +610,6 @@ - - - - - - - - - - @@ -644,5 +620,25 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cookbook/forms.py b/cookbook/forms.py index 679484b19..9596707b1 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -14,7 +14,6 @@ class RecipeForm(forms.ModelForm): 'name': _('Name'), 'category': _('Category'), 'keywords': _('Keywords'), - } help_texts = { @@ -62,12 +61,13 @@ class KeywordForm(forms.ModelForm): self.helper.add_input(Submit('save', _('Save'), css_class='btn-primary')) -class EditCategoryForm(forms.ModelForm): +class EditRecipeForm(forms.ModelForm): class Meta: - model = Keyword - fields = ('name', 'description') + model = Recipe + fields = ('name', 'category', 'keywords') labels = { 'name': _('Name'), - 'description': _('Description'), + 'category': _('Category'), + 'keywords': _('Keywords'), } diff --git a/cookbook/tables.py b/cookbook/tables.py index 7d28904c7..98990d9d4 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -24,7 +24,7 @@ class CategoryTable(tables.Table): class KeywordTable(tables.Table): id = tables.LinkColumn('edit_recipe', args=[A('id')]) - + class Meta: model = Keyword template_name = 'tables/table_template.html' diff --git a/cookbook/views.py b/cookbook/views.py index f2e4e777c..26b93ca23 100644 --- a/cookbook/views.py +++ b/cookbook/views.py @@ -21,7 +21,19 @@ def index(request): @login_required def edit_recipe(request, id): - return render(request, 'index.html') + if request.method == "POST": + form = RecipeForm(request.POST) + if form.is_valid(): + recipe = form.save(commit=False) + recipe.created_by = request.user.id + recipe.save() + form.save_m2m() + return redirect('edit_recipe/' + id) + else: + recipe = Recipe.objects.get(id=id) + form = EditRecipeForm(instance=recipe) + + return render(request, 'new_recipe.html', {'from': form}) @login_required