I have a view, which creates models from CSV file. I\'ve added clean method to the model class definition, but it isn\'t called when model is created.
Here is exampl
I've found a solution to override method:
class CommonMeasurement(models.Model):
timestamp = models.DateTimeField()
value = models.FloatField()
run = models.ForeignKey(Run)
objects = models.Manager()
analyzes = managers.MeasureStatManager()
def save(self, **kwargs):
self.clean()
return super(CommonMeasurement, self).save(**kwargs)
def clean(self):
super(CommonMeasurement, self).clean()
print 'here we go'
if self.timestamp < self.run.timestamp_start or self.timestamp > self.run.timestamp_end:
raise django_excetions.ValidationError('Measurement is outside the run')
But I'm not sure that it can be a good decision.