fixup! Add forms for adding recipes and versions
Check for slug uniqueness
This commit is contained in:
parent
acbcf3f606
commit
312c02cd51
|
|
@ -1,4 +1,4 @@
|
|||
from django.forms import ModelForm, BooleanField
|
||||
from django.forms import ModelForm, BooleanField, ValidationError
|
||||
from .models import Recipe, Version, Ingredient
|
||||
|
||||
class VersionForm(ModelForm):
|
||||
|
|
@ -6,4 +6,10 @@ class VersionForm(ModelForm):
|
|||
model = Version
|
||||
fields = ['label', 'slug', 'body']
|
||||
|
||||
def clean_slug(self):
|
||||
slug = self.cleaned_data['slug']
|
||||
if Version.objects.filter(slug=slug).exists():
|
||||
raise ValidationError('A recipe version with this slug already exists.')
|
||||
return slug
|
||||
|
||||
# use_author_user = BooleanField(initial=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue