I want to add a locale selection to the default django-registration. I tried to follow this tutorial from dmitko. The form shows up correctly but the additional data (locale) is not saved.
I defined a custom model:
class AnymalsProfile(models.Model):
user = models.ForeignKey(User, unique=True)
locale = models.CharField(max_length=2)
def __unicode__(self):
return u'%s %s' % (self.user, self.locale)
and the form:
from models import AnymalsProfile
from registration.forms import RegistrationFormTermsOfService
class UserRegistrationForm(RegistrationFormTermsOfService):
locale = forms.CharField(max_length=3, widget=forms.Select(choices=LOCALE_CHOICES),label='Language:')
The fields show up correctly, but the locale data (profile) is not saved. I assume that the regbackend.py is my problem:
from anysite.models import AnymalsProfile
def user_created(sender, user, request, **kwargs):
form = UserRegistrationForm(request.POST)
data = AnymalsProfile(user=user)
data.locale = form.cleaned_data["locale"]
data.save()
from registration.signals import user_registered
user_registered.connect(user_created)
* EDIT * I tried moving into production - just for a test - and it raised some errors. I altered the code, but still the profile is not saved. Here is what I tried:
from anysite.models import AnymalsProfile
from anysite.forms import UserRegistrationForm
def user_created(sender, user, request, **kwargs):
form = UserRegistrationForm(request.POST)
if form.is_valid():
ProfileData = form.cleaned_data
profile = AnymalsProfile(
user = user.id,
locale = ProfileData["locale"]
)
profile.save()
from registration.signals import user_registered
user_registered.connect(user_created)