📜  django 刷新表单 db - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:14.391000             🧑  作者: Mango

代码示例1
def test_update_result(self):
    obj = MyModel.objects.create(val=1)
    MyModel.objects.filter(pk=obj.pk).update(val=F('val') + 1)
    # At this point obj.val is still 1, but the value in the database
    # was updated to 2. The object's updated value needs to be reloaded
    # from the database.
    obj.refresh_from_db()
    self.assertEqual(obj.val, 2)