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.
26 lines
1.0 KiB
26 lines
1.0 KiB
from django import forms
|
|
|
|
from apps.payment.models import Discount
|
|
|
|
|
|
class DiscountAdminForm(forms.ModelForm):
|
|
|
|
def clean(self):
|
|
clean_data = super().clean()
|
|
|
|
if clean_data['product'] == Discount.PRODUCT_ONE_COURSE and clean_data.get('course') is None:
|
|
self.add_error('course', 'Не выбран курс')
|
|
if clean_data['product'] == Discount.PRODUCT_ONE_PACKAGE and clean_data.get('package') is None:
|
|
self.add_error('package', 'Не выбрана подписка')
|
|
|
|
if clean_data['usage_type'] == Discount.USAGE_TYPE_LIMIT:
|
|
if clean_data.get('usage_count_limit') is None:
|
|
self.add_error('usage_count_limit', 'Не указан лимит использования')
|
|
elif clean_data['usage_count_limit'] == 0:
|
|
self.add_error('usage_count_limit', 'Лимит использования равен 0')
|
|
return clean_data
|
|
|
|
class Meta:
|
|
model = Discount
|
|
fields = '__all__'
|
|
exclude = ['author']
|
|
|