我找到了覆盖方法的解决方案:
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')
但是我不确定这是否是一个好决定。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)