fixup! Add forms for adding recipes and versions
fix slug bug
This commit is contained in:
parent
deb8d339d6
commit
bb01945c6c
|
|
@ -9,10 +9,11 @@ class VersionForm(ModelForm):
|
||||||
fields = ['label', 'slug', 'body', 'author']
|
fields = ['label', 'slug', 'body', 'author']
|
||||||
|
|
||||||
def clean_slug(self):
|
def clean_slug(self):
|
||||||
recipe = Recipe.objects.get(id=self.recipe_id)
|
|
||||||
slug = self.cleaned_data['slug']
|
slug = self.cleaned_data['slug']
|
||||||
if recipe.versions.filter(slug=slug).count() > 0: # type: ignore
|
if 'slug' in self.changed_data:
|
||||||
raise ValidationError('A recipe version with this slug already exists.')
|
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
|
return slug
|
||||||
|
|
||||||
class IngredientForm(ModelForm):
|
class IngredientForm(ModelForm):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue