Fix AttributeError bug

This commit is contained in:
Benjamin 2023-03-25 09:12:51 +01:00
parent 480ec82a96
commit 446486bf0d

View file

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