From 446486bf0d996f6dbb23634d81584cfd29b03e0c Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 25 Mar 2023 09:12:51 +0100 Subject: [PATCH] Fix AttributeError bug --- recipes/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/forms.py b/recipes/forms.py index 9889b55..df243c4 100644 --- a/recipes/forms.py +++ b/recipes/forms.py @@ -26,7 +26,7 @@ class RecipeForm(ModelForm): fields = ['title', 'slug'] class VersionForm(ModelForm): - recipe_id: int + recipe_id: int = 0 def __init__(self, *args, **kwargs): placeholder = None @@ -42,7 +42,7 @@ class VersionForm(ModelForm): def clean_slug(self): slug = self.cleaned_data['slug'] - if 'slug' in self.changed_data: + if 'slug' in self.changed_data and self.recipe_id: recipe = Recipe.objects.get(id=self.recipe_id) if recipe.versions.filter(slug=slug).count() > 0: # type: ignore raise ValidationError('A recipe version with this slug already exists.')