【发布时间】:2018-09-24 04:51:11
【问题描述】:
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
p.s:我的模型正在正常保存,只是没有达到我的预期。
【问题讨论】:
-
请向模型管理员展示您在哪里使用表单,以及您是如何注册该模型管理员的。
标签: django django-admin