如何在添加或编辑记录时捕获Django管理站点中的异常触发器? 例如,我有模型
class Flight(models.Model):
flight_num = models.CharField(max_length=10, primary_key=True)
departure = models.CharField(max_length=30)
arrival = models.CharField(max_length=30)
departure_time = models.TimeField()
arrival_time = models.TimeField()
def __str__(self):
return self.flight_num
并在PostgreSQL 9.1中触发
BEGIN
if (NEW.departure_time > NEW.arrival_time)
then raise EXCEPTION 'It's unreal';
end if;
RETURN NEW;
END;
该模型已在admin.site中注册。谢谢。