Django pre_save没有保存更改

时间:2017-02-03 13:59:20

标签: django

我需要在保存模型之前修改一些值:

@receiver( pre_save )
def model_pre_save( sender, instance, *args, **kwargs ):
    print instance.path # prints "old_path"
    instance.path = some_path()
    print instance.path # prints "new_path"

但保存instance.path后仍然等于"old_path"

1 个答案:

答案 0 :(得分:4)

pre_save 实例更改未通过,您应该根据文档使用update_fields

pre_save