You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
628 B

from django import forms
from .models import Product
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = '__all__'
def clean_shelf_life_days(self):
shelf_life_days = self.cleaned_data.get('shelf_life_days')
if shelf_life_days <= 0:
raise forms.ValidationError("Срок годности должен быть положительным числом.")
if shelf_life_days > 3650: # 10 лет
raise forms.ValidationError("Срок годности превышает допустимый предел.")
return shelf_life_days