1

Can someone help me with this? I try to add a validation like the following:

start_date < end_date

These variables are datetime type. I hope someone already did this validation.

date_start = models.DateTimeField(
    verbose_name=_("start date")
)
date_end = models.DateTimeField(
    blank=True, null=True, verbose_name=_("end date")
)
oshingc
  • 341
  • 2
  • 5
  • 13
  • You could do the validation when you create your object instead of inside the model. If you want to validate it inside the model you can override clean, take a look at this question : https://stackoverflow.com/questions/12945339/is-this-the-way-to-validate-django-model-fields – Yacine Mahdid Feb 07 '20 at 18:54
  • What would be the result if `date_end` value is **`None`** ? – JPG Feb 07 '20 at 19:48

0 Answers0