I'm using Django Registration(https://bitbucket.org/ubernostrum/django-registration/), and I need to add some fields to the registration of users.
I've made a subclass of the RegistrationForm. My "forms.py" is the following:
from django.contrib.auth.models import User
from myproject.apps.userprofile.models import Gender, UserProfile
from myproject.apps.location.models import Country, City
from django import forms
from registration.forms import RegistrationForm
from registration.models import RegistrationManager
class RegistrationFormExtend(RegistrationForm):
"""
Subclass of ``RegistrationForm`` which adds the fiedls in the userprofile app
"""
gender = forms.ModelChoiceField(queryset=Gender.objects.all(), empty_label="(Nothing)")
country = forms.ModelChoiceField(queryset=Country.objects.all(), empty_label="(Nothing)")
city = forms.ModelChoiceField(queryset=City.objects.all(), empty_label="(Nothing)")
#profile_picture =
To make it work I've changed the "urls.py" to show the "RegistrationFormExtend" form by adding the "form_class" parameter to the "register" view:
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from registration.views import activate
from registration.views import register
from myproject.apps.registrationextend.forms import RegistrationFormExtend
urlpatterns = patterns('',
...
url(r'^registar/$',
register,
{'backend': 'registration.backends.default.DefaultBackend', 'form_class': RegistrationFormExtend,},
name='registration_register'),
...
)
After that, I've tested and the form is working. The user is registered successfully, but all the extra fields(gender, country, city) in the "RegistrationFormExtend" are NOT stored in the database.
Reading the documentation, http://docs.b-list.org/django-registration/0.8/views.html#registration.views.register it seems that I must to pass the parameter "extra_context" to the view.
My question is how to pass a dictionary to the "extra_context" parameter. How to refer to the variables "gender", "country" and "city"?
Thanks in advance.