16 lines
459 B
Python
16 lines
459 B
Python
from django.forms import ModelForm, BooleanField, ValidationError
|
|
from .models import Recipe, Version, Ingredient
|
|
|
|
class VersionForm(ModelForm):
|
|
class Meta:
|
|
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)
|