H
H
hardwellZero2015-06-10 14:41:21
Django
hardwellZero, 2015-06-10 14:41:21

How to add another field during registration?

Hello.
I want to add one more field when registering a user, namely phone.
models.py

from django.db import models
from django.contrib.auth.models import User

class CustomUserPhone(models.Model):
    user = models.ForeignKey(User)
    phone = models.CharField(max_length=25)

urls.py
urlpatterns = patterns('',

    url(r'^$',
        TemplateView.as_view(template_name='index.html'),
        name='index'),

    url(r'^registration/$',
        RegistrationView.as_view(form_class=RegistrationFormUniqueEmail),
        name='registration_register'),

    url(r'^accounts/',
        include('registration.backends.default.urls')),

    url(r'^profile/',
        TemplateView.as_view(template_name='profile.html'),
        name='profile'),

    url(r'^login/',
        'django.contrib.auth.views.login',
        name='login'),

    url(r'^logout/',
        'django.contrib.auth.views.logout',
        name='logout')
)

Now the form looks like this:
aedd162d236d4f4691c20ededf86938a.png
I want to add one more field here, which will be responsible for the user's phone number and goes into the database (table app_customuserphone). Oh yeah, I'm using django-registration-redux / Django 1.8.
What is needed for this? Found outdated articles on Django 1.4 and django-registration (previous version).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-06-10
@hardwellZero

Reload the RegistrationFormUniqueEmail form, add your field there and the logic for saving the CustomUserPhone model.
In general, it would be better to make a custom user model and simply add this field there, and not to fence one-to-one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question