为什么django 的model.save() 不调用full_clean()? - Why doesn't django's model.save() call full_clean()?

2021/11/30 10:13
阅读数 0

问题:

I'm just curious if anyone knows if there's good reason why django's orm doesn't call 'full_clean' on a model unless it is being saved as part of a model form.我只是很好奇是否有人知道 django 的 orm 是否有充分的理由不在模型上调用“full_clean”,除非它被保存为模型表单的一部分。

Note that full_clean() will not be called automatically when you call your model's save() method.请注意,当您调用模型的 save() 方法时,不会自动调用 full_clean()。 You'll need to call it manually when you want to run one-step model validation for your own manually created models.当您想要为您自己手动创建的模型运行一步模型验证时,您需要手动调用它。 django's full clean doc django 的完整清洁文档

(NOTE: quote updated for Django 1.6... previous django docs had a caveat about ModelForms as well.) (注意:为 Django 1.6 更新了报价......之前的 django 文档也有关于 ModelForms 的警告。)

Are there good reasons why people wouldn't want this behavior?人们不想要这种行为是否有充分的理由? I'd think if you took the time to add validation to a model, you'd want that validation run every time the model is saved.我认为如果您花时间向模型添加验证,您会希望每次保存模型时都运行该验证。

I know how to get everything to work properly, I'm just looking for an explanation.我知道如何让一切正常工作,我只是在寻找一个解释。


解决方案:

参考: https://stackoom.com/en/question/IdRj
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部