django 管理员实际上在哪里保存它的模型?
我想打印一些仅在保存后创建的模型字段,但 UserCreationForm 保存方法总是使用 commit=False 调用,并且似乎返回用户,因此保存发生在其他地方。
class MyUserCreationForm(UserCreationForm):
...
def save(self, commit=True):
# django admin calling this with commit=False... save occurs somewhere else.
...
if commit:
print("this never gets printed")
user.save()
# line below prints nothing
print(user.field_set_after_model_is_saved)
return user
Run Code Online (Sandbox Code Playgroud)
ps:我的模型正常保存,只是没有达到我的预期。