19 lines
543 B
Python
19 lines
543 B
Python
from django.forms import ModelForm, BooleanField, ValidationError
|
|
from .models import Recipe, Version, Ingredient
|
|
|
|
class VersionForm(ModelForm):
|
|
recipe_id: int
|
|
|
|
class Meta:
|
|
model = Version
|
|
fields = ['label', 'slug', 'body']
|
|
|
|
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.')
|
|
return slug
|
|
|
|
# use_author_user = BooleanField(initial=True)
|