【发布时间】:2016-07-21 22:44:23
【问题描述】:
我有两个 ModelForms。一个 UserForm 和一个 ProfileForm。我不知道如何将表单数据保存到用户对象配置文件中。
这是我在通用视图中的 post 函数中的一些外观:
user = user_form.save(commit=False)
profile = profile_form.save(commit=False)
password = user_form.cleaned_data['password']
user.set_password(password)
user.is_active = False
user.is_staff = True
user.save()
我尝试使用以下方式保存配置文件:
about = profile_form.cleaned_data['about']
user.profile.about = about
但这没有用。我得到了User has no profile. 我如何保存数据?
【问题讨论】:
-
你把这个整理出来了吗?
标签: django