Fix AttributeError bug
This commit is contained in:
parent
480ec82a96
commit
446486bf0d
|
|
@ -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.')
|
||||
|
|
|
|||
Loading…
Reference in a new issue