fixup! Add forms for adding recipes and versions
fix slug bug
This commit is contained in:
parent
deb8d339d6
commit
bb01945c6c
|
|
@ -9,8 +9,9 @@ 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 '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
|
||||
|
|
|
|||
Loading…
Reference in a new issue