forms.py 491 B

1234567891011121314151617
  1. from django.forms import ModelForm
  2. from django.core.exceptions import ValidationError
  3. from .models import Payment
  4. class PaymentForm(ModelForm):
  5. class Meta:
  6. model = Payment
  7. fields = ['amount', 'period', 'payment_method', 'start']
  8. def clean_start(self):
  9. start = self.cleaned_data['start']
  10. if self.instance.pk:
  11. if start < self.instance.start:
  12. raise ValidationError(_('Invalid value'), code='invalid')
  13. return start