I have a problem with a model\'s clean() method and basic field validation. here\'s my model and the clean() method.
class Trial(mo
I'm struggling with a similar issue but with a ForeignKey. In your case, I would just check that the fields are not empty, and I would simplify your Boolean expressions:
class Trial(models.Model):
trial_start = DurationField()
movement_start = DurationField()
trial_stop = DurationField()
def clean(self):
from django.core.exceptions import ValidationError
if self.trial_start:
if self.movement_start and self.movement_start < self.trial_start:
raise ValidationError('movement start must be >= trial start')
if self.trial_stop:
if self.trial_stop <= self.trial_start:
raise ValidationError('trial stop must be > trial start')
if self.movement_start:
if self.trial_stop < self.movement_start:
raise ValidationError('trial stop must be >= movement start')