Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- period_from = models.DateField(verbose_name='From')
- period_to = models.DateField(verbose_name='To')
- class AdminBillForm(ModelForm):
- class Meta:
- model = Bill
- exclude = ()
- def clean_period_from(self):
- period_from = self.cleaned_data.get('period_from')
- if (period_from >= timezone.now().date()):
- raise ValidationError("'From' date cannot be a future date.")
- return period_from
- def clean_period_to(self):
- period_to = self.cleaned_data.get('period_to')
- if (period_to > timezone.now().date()):
- raise ValidationError("'To' date cannot be a future date.")
- return period_to
- def clean(self):
- cleaned_data = super(AdminBillForm, self).clean()
- period_from = cleaned_data.get('period_from')
- period_to = cleaned_data.get('period_to')
- if (period_from >= period_to):
- raise ValidationError("'From' date should not be beyond 'To' date.")
- @admin.register(Bill)
- class BillAdmin(admin.ModelAdmin):
- form = AdminBillForm
- '>=' not supported between instances of 'NoneType' and 'datetime.date'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement