Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. period_from = models.DateField(verbose_name='From')
  2. period_to = models.DateField(verbose_name='To')
  3.  
  4. class AdminBillForm(ModelForm):
  5. class Meta:
  6. model = Bill
  7. exclude = ()
  8.  
  9. def clean_period_from(self):
  10. period_from = self.cleaned_data.get('period_from')
  11. if (period_from >= timezone.now().date()):
  12. raise ValidationError("'From' date cannot be a future date.")
  13. return period_from
  14.  
  15. def clean_period_to(self):
  16. period_to = self.cleaned_data.get('period_to')
  17. if (period_to > timezone.now().date()):
  18. raise ValidationError("'To' date cannot be a future date.")
  19. return period_to
  20.  
  21. def clean(self):
  22. cleaned_data = super(AdminBillForm, self).clean()
  23.  
  24. period_from = cleaned_data.get('period_from')
  25. period_to = cleaned_data.get('period_to')
  26.  
  27. if (period_from >= period_to):
  28. raise ValidationError("'From' date should not be beyond 'To' date.")
  29.  
  30. @admin.register(Bill)
  31. class BillAdmin(admin.ModelAdmin):
  32. form = AdminBillForm
  33.  
  34. '>=' not supported between instances of 'NoneType' and 'datetime.date'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement