Q:

How to create a collection of fields from two Django forms?

I am trying to create a custom user registration form in Django 1.8.3. The thing I want to achieve is a form that consists of two separate forms based on two separate models. The first model is the default Django User model and the form based on it contains username, email, first_name, last_name, password1 and password2 fields. The second model is UserDetails and for now it contains only three fields - user (which should store a foreign key - user id), middle_name and phone_number.  I would like to create a template that will display fields of these two forms in following order: 

username,
email, 
phone_number,
first_name,
middle_name, 
last_name, 
password1, 
password2.

The question is: Is there any way to create a list (or any other collection) of those fields which I could later iterate over to make them displayed in this particular order? I tried to create instances of my forms:
registration_form = RegistrationForm()
user_details_form = UserDetailsForm()

and a list of their fields in my custom order:
fields = [registration_form.username, 
          registration_form.email, 
          user_details_form.phone_number,
          registration_form.first_name,
          ...]

Then I tried to display fields in HTML file using following code:
{% for field in fields %}
    {{ field }}
    {{ field.help_text }}
    {{ field.errors }}
{% endfor %}

but it didn't work - I got the following error:

AttributeError at /register 'RegistrationForm' object has no attribute
  'username'

A:

You cannot simply combine two forms using django's ModelForm.
What you can do instead is extend RegistrationForm class by adding custom user fields from UserDetails model. Then override all needed methods (clean, save, etc) to include those custom fields in your flow.
To reorder the fields, you need to extend/override Meta class inside the new form class.
Example:
class UserDetailsForm(RegistrationForm):
    middle_name = ...
    phone_number = ...

    class Meta:
        model = User
        fields = ('username', ..., 'password2')

I'm assuming your RegistrationForm form is based on django's ModelForm

