WimDH
WimDH

Reputation: 65

Django 1.9 Crispy forms 1.6: multiple forms issue

I 'm writing an app in Django 1.9 and installed Crispy forms 1.6 (using bootstrap3 template pack). In that app, I have a profile model, next to the standard User model. Now, I want to allow the users to modify their profile, and I want to display both User fields and Profile fields on one page. The Profile model contains an avatar, which I want to display on to of the page, followed by some fields from the User model, and after that the rest of the Profile form's fields. Something like:

> Avatar (Profile model)
> First name (User model)
> Last name (User model)
> E-mail address (User model)
> Street (Profile model)
> ZIP (Profile model)
> Country (Profile model)
> Website (Profile model)

I've written 2 Forms:

class UserForm(forms.ModelForm)
class ProfileForm(forms.ModelForm)

Both extended with the Crispy forms "FormHelper"

In my template, I render the forms as: {% crispy pform %} (profile form) {% crispy uform %} (user form)

But, of course, that does not display the fields as I described earlier.

Does anyone know how I can tackle this problem?

Kind regards!

Wim

Upvotes: 0

Views: 540

Answers (1)

durdenk
durdenk

Reputation: 1660

Why you dont create a form as you desire and render fields one by one?

<form>
    {{ pform.avatar|as_crispy_field }}
    {{ uform.first_name|as_crispy_field }}
    ...
</form>

You may want to initialize forms with different prefixes.

Upvotes: 2

Related Questions