有这个代码:
class SomeModel(models.Model):
pass
class OtherModel(models.Model):
some_model = models.ForeignKey(SomeModel)
om = OtherModel()
if om.some_model:
pass
抛出的异常是:
models.DoesNotExist
是否有一些很好的方法来检查是否设置了外键对象而不是 try...except 或 hasattr?