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.')