how add new fields in registration form ? had hard time find out sharing here
-- forms.py:
from registration.forms import registrationform class userprofileregistrationform(registrationform): first_name = forms.charfield(max_length=15, label='first name') last_name = forms.charfield(max_length=15, label='last name') date_of_birth = forms.datefield(label='date of birth', widget=selectdatewidget(years=[y y in range(1950, datetime.datetime.now().year-17)], attrs=({'style': 'width: 33%; display: inline-block;'})),) class meta: model = usermodel() fields = (usernamefield(), "email", 'first_name', 'last_name', 'date_of_birth')
-- views.py
from registration.views import registrationview class userprofileregistration(registrationview): success_url = '/' form_class = userprofileregistrationform def register(self, form): """ implement user-registration logic here. """ user = usermodel() user = user.objects.create_user( username = form.cleaned_data['username'], first_name = form.cleaned_data['first_name'], last_name = form.cleaned_data['last_name'], email=form.cleaned_data['email'], password=form.cleaned_data['password1'] )
note: if want user login automatically use this: https://djangosnippets.org/snippets/1547/
-- urls.py
from myapp.views import userprofileregistration url(r'^accounts/register/$', userprofileregistration.as_view(), name='registration_register'), url(r'^accounts/', include('registration.backends.simple.urls')),
thanks drjackild. reference: https://github.com/macropin/django-registration/issues/73
Comments
Post a Comment