I am trying to use django-allauth for user registrations. I have this form
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('gender', 'country', 'city', 'birth_date', 'has_accepted_tos')
and as per instructions I have set in my settings.py
ACCOUNT_SIGNUP_FORM_CLASS = "userprofile.forms.UserProfileForm"
The problem is that when the form is rendered my custom form asking for gender, country etc is rendered on top and then the standard User fields that ask for username, email and password. Something in this order:
gender
country
city
birth_date
has_accepted_tos
username
password1
password2
I would like to display the fields in this order
username
password1
password2
gender
country
etc
You need to provide the field_order
attribute:
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('gender', 'country', 'city', 'birth_date', 'has_accepted_tos')
field_order = ['username', 'email', 'password1', 'password2', 'gender', 'country']
However, a better practice would be to use the template file to render the form exactly as you want to.
Quoting the project author:
(...) Then again, I would not put too much weight on what allauth has to offer out of the box display/design wise. All of this is just for reference, the idea is that you create a proper design & form layout in your templates.
References:
[1] https://github.com/pennersr/django-allauth/blob/master/allauth/account/forms.py
[2] https://github.com/pennersr/django-allauth/issues/269
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With