I have already looked through all the django registration examples and i've successfully created a form with extended fields but i've experienced a few problems listed below, mainly with the data not being saved in the DB table UserProfile.
I created a forms.py and stored in my proj directory.
It's as follows:
from django import forms
from r2.models import Keyword
from r2.models import UserProfile
from registration.forms import RegistrationForm
from registration.models import RegistrationProfile
from django.utils.translation import ugettext_lazy as _
from registration.forms import RegistrationForm, attrs_dict
class ProjectSpecificRegistrationForm(RegistrationForm):
keywords = forms.ModelChoiceField(queryset=Keyword.objects.all())
first_name =forms.CharField(widget=forms.TextInput(attrs=attrs_dict),label=_(u'First Name'))
last_name =forms.CharField(widget=forms.TextInput(attrs=attrs_dict),label=_(u'Last Name'))
def save(self, profile_callback=None):
new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email=self.cleaned_data['email'])
new_profile = UserProfile(user=new_user,username=self.cleaned_data['username'], keywords_subscribed=self.cleaned_data['keywords'],first_name=self.cleaned_data['first_name'],last_name=self.cleaned_data['last_name'])
new_profile.save()
and the URLS.py:
#registrations URLS
url(r'^activate/(?P<activation_key>\w+)/$',activate,name='registration_activate'),
url(r'^login/$',auth_views.login,{'template_name': 'registration/login.html'}, name='auth_login'),
url(r'^logout/$',auth_views.logout,{'template_name': 'registration/logout.html'},name='auth_logout'),
url(r'^password/change/$',auth_views.password_change,name='auth_password_change'),
url(r'^password/change/done/$',auth_views.password_change_done,name='auth_password_change_done'),
url(r'^password/reset/$',auth_views.password_reset,name='auth_password_reset'),
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',auth_views.password_reset_confirm,name='auth_password_reset_confirm'),
url(r'^password/reset/complete/$',auth_views.password_reset_complete,name='auth_password_reset_complete'),
url(r'^password/reset/done/$',auth_views.password_reset_done,name='auth_password_reset_done'),
url(r'^register/$',register, {'backend': 'accounts.regbackend.RegBackend','form_class' : ProjectSpecificRegistrationForm}, name='registration_register'),
url(r'^register/complete/$',direct_to_template,{'template': 'registration/registration_complete.html'},name='registration_complete'),
I've added all these to the proj urls.py as i've followed a tutorial from somewhere.
Problem 1: User profile is not getting saved into the DB even though i am using django registration 0.6.
Problem 2: Is this the correct way to set my urls.py? because i understand i'm not supposed to overwrite the registration urls.py.
Problem 3: Must i create a regbackend.py? and if so how do i go about doing that?