diff --git a/recipes/forms.py b/recipes/forms.py index 0aa8b64..c7731f7 100644 --- a/recipes/forms.py +++ b/recipes/forms.py @@ -9,10 +9,11 @@ class VersionForm(ModelForm): fields = ['label', 'slug', 'body', 'author'] def clean_slug(self): - recipe = Recipe.objects.get(id=self.recipe_id) slug = self.cleaned_data['slug'] - if recipe.versions.filter(slug=slug).count() > 0: # type: ignore - raise ValidationError('A recipe version with this slug already exists.') + if 'slug' in self.changed_data: + 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.') return slug class IngredientForm(ModelForm):