
在Django源代码中,_state是在每个Model实例中定义的实例变量,该实例变量的实例
ModelState定义为:
class ModelState(object): """ A class for storing instance state """ def __init__(self, db=None): self.db = db # If true, uniqueness validation checks will consider this a new, as-yet-unsaved object. # Necessary for correct validation of new instances of objects with explicit (non-auto) PKs. # This impacts validation only; it has no effect on the actual save. self.adding = True
因此,基本上,该实例变量用于了解
Model实例是否已写入
db(知道Django支持多个数据库后端)并保存
db使用的实例变量,该实例变量属性
adding在保存模型实例后设置为false
,并且大多数情况下使用(作为上面代码中的注释),用于验证主键是否唯一。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)