1

please help change the order of the form fields on the screen.

I created the following model:

class UserProfile(User):
    status = models.CharField(
        max_length=30, 
        blank=True,
    )

    address = models.EmailField(
        max_length=50, 
        blank=True,
    )   

    objects = UserManager()

then combined field of this model built with fields of the registration form:

class MyRegistrationForm(UserCreationForm): 
    username = forms.CharField(
        label='username',
        help_text='',
        required=True,
    )

    password1 = forms.CharField(
        label='pass1',
        help_text='',
        required=True,
    )   

    password2 = forms.CharField(
        label='pass2',
        help_text='',
        required=True,
    )   

    class Meta:
        model = UserProfile
        fields = ('status', 'address')

as a result the user sees on the display field in this order: status, address, username, pass1, pass2

but I need the user to see the screen fields in the following order: username, address, pass1, pass2, status

dizzy
  • 29
  • 4

1 Answers1

1

According to the documentation:

The generated Form class will have a form field for every model field specified, in the order specified in the fields attribute.

class MyRegistrationForm(UserCreationForm): 
    ...
    class Meta:
        model = UserProfile
        fields = ('username', 'address', 'password1', 'password2', 'status')

See also: How can I order fields in Django ModelForm?

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195