-1

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?

Stanwin Siow
  • 437
  • 1
  • 8
  • 21
  • I wish I knew more about django-registration. From looking over the [quick start guide in the docs](https://bitbucket.org/ubernostrum/django-registration/src/fad7080fe769/docs/quickstart.rst), it seems like the most basic setup doesn't require you to add much to urls.py or to write any forms, though. – dokkaebi Mar 04 '12 at 05:39
  • It might help if you can clarify a couple things. What did you try that you expect to cause User profile to be saved? Do you go to the frontend of your site and register as a new user? What else happens when you try? Any errors? Do you see 201 created or other messages in the server output that could help? – dokkaebi Mar 04 '12 at 05:42
  • well @dokkaebi in the original django-registration form, i was able to save the user profile by calling this method 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() but it's not happening because of how i overridden the registration form. – Stanwin Siow Mar 04 '12 at 06:00

0 Answers0