Django 如何使用OneTONE字段保存表单向导

Django 如何使用OneTONE字段保存表单向导,django,forms,formwizard,Django,Forms,Formwizard,Django 1.6 我有两种型号: 用户标准模型 轮廓 代码: 我使用表单向导注册用户。首先,用户输入用户名和密码。接下来,他编写配置文件字段。如何将此信息保存到模型中。 我的看法是: forms.py: class UserRegistrationForm(UserCreationForm): class Meta: model = User fields = ['username', 'password1'] class UserRegistrationForm1(form

Django 1.6 我有两种型号:

用户标准模型 轮廓 代码:

我使用表单向导注册用户。首先,用户输入用户名和密码。接下来,他编写配置文件字段。如何将此信息保存到模型中。 我的看法是:

forms.py:

class UserRegistrationForm(UserCreationForm):
class Meta:
    model = User
    fields = ['username', 'password1']
class UserRegistrationForm1(forms.ModelForm):
class Meta:
    model = Profile
    fields = ['first_name', 'last_name', 'email', 'bdate', 'phone']
模板:

{% block reg_usr %}
<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
{% for field in form %}
    {{ field.error }}
{% endfor %}
<form method="post">{% csrf_token %}
    <table>
        {{ wizard.management_form }}
        {% if wizard.form.forms %}
            {{ wizard.form.management_form %}
            {% for form in wizard.form.forms %}
                {{ form }}
            {% endfor %}
        {% else %}
            {{ wizard.form }}
        {% endif %}
        </table>
        {% if wizard.steps.prev %}
        <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">First step</button>
        <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">Prev step</button>
        {% endif %}
    <input type="submit" value="Next"/>
</form>

{%endblock%}

您尝试了什么?到目前为止你有任何代码吗?我要注册用户。有两个页面的表单向导。第一页-用户名和密码注册,第二页-用户信息-姓名、lats姓名、电子邮件和电话。我想把这个保存到基地。但我无法保存用户信息,因为我没有用户id。如何从第二页获取用户id并保存配置文件信息。谢谢。请尝试保存表单列表[1]以获取/创建用户,然后保存表单列表[0]。我必须具有用户id才能将表单列表[1]保存到基中。@Vitek表单列表[0]的返回值。保存应为用户对象本身。只需使用其id分配到配置文件中。
class UserRegistrationForm(UserCreationForm):
class Meta:
    model = User
    fields = ['username', 'password1']
class UserRegistrationForm1(forms.ModelForm):
class Meta:
    model = Profile
    fields = ['first_name', 'last_name', 'email', 'bdate', 'phone']
{% block reg_usr %}
<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
{% for field in form %}
    {{ field.error }}
{% endfor %}
<form method="post">{% csrf_token %}
    <table>
        {{ wizard.management_form }}
        {% if wizard.form.forms %}
            {{ wizard.form.management_form %}
            {% for form in wizard.form.forms %}
                {{ form }}
            {% endfor %}
        {% else %}
            {{ wizard.form }}
        {% endif %}
        </table>
        {% if wizard.steps.prev %}
        <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">First step</button>
        <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">Prev step</button>
        {% endif %}
    <input type="submit" value="Next"/>
</form>