Answer the question
In order to leave comments, you need to log in
NotImplementedError, Adding custom fields to django-registration?
Good evening. I already asked here about adding two fields to the standard django-registration (not redux) form. Essence of the question: it is necessary to give the user on a level with username , password , email to enter available in the standard User class last_name, first_name.
And so it was done:
forms.py
from registration.forms import RegistrationForm
from django.forms.fields import CharField
from django.contrib.auth.models import User
class UpdatedRegistrationForm(RegistrationForm):
first_name = CharField(max_length=20)
last_name = CharField(max_length=30)
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
def save(self, commit = True):
user = super(UpdatedRegistrationForm, self).save(commit=False)
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
if commit:
user.save()
return user
from django.conf.urls import include, url
from django.contrib import admin
from accounts.views import home_page, admin_panel
from accounts.forms import UpdatedRegistrationForm
from registration.views import RegistrationView
class RegistrationViewUniqueEmail(RegistrationView):
form_class = UpdatedRegistrationForm
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^home/', home_page),
url(r'^admin_pannel/',admin_panel),
url(r'^register/$', RegistrationViewUniqueEmail.as_view(), name='registration_register'),
url(r'', include('registration.backends.simple.urls')),
url(r'', include('social_auth.urls')),
]
Answer the question
In order to leave comments, you need to log in
There is clearly an error here.
if commit:
user.save()
return user
if commit:
user.save()
return user
from registration.backends.default.views import RegistrationView
but notfrom registration.views import RegistrationView
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question