我正在使用Django == 1.11.3,如果在访问实例方法时引发异常,它将删除对象。下面是一个示例
class SomeModel(models.Model):
key = models.CharField(max_length=250)
response = models.TextField(blank=True, null=True)
@classmethod
def add_api_response(cls, key, response):
obj = cls.objects.create(
key=key,response=response
)
return obj
response_data = SomeModel.add_api_response(
key=some_key,
response=some_response
)
# ^ above codes creates a object with id `x`
response_data.get() # OR response_data.any_unknown()
# ^ above codes deletes it
我是Django的新手,请指导其预期行为,即它在引发异常时删除了该模型,还是我应该丢失任何异常挂钩?
预先感谢您的帮助