django-registration custom fields

1,599 views
Skip to first unread message

Pankaj Singh

unread,
May 29, 2010, 7:11:19 AM5/29/10
to Django users
Hi
I want to extend django-registration form by adding fields like

first name
last name
date of birth
country
languages you speak etc.

for my project ..

how should i proceed for this ..

--
--
--
Thanking You,

Pankaj Kumar Singh,
2nd Year Undergraduate Student,
Department of Agricultural and Food Engineering,
Indian Institute of Technology,
Kharagpur

Mobile - (+91) 8001231685

Pankaj Singh

unread,
May 29, 2010, 7:41:08 AM5/29/10
to Django users
I tried extending RegistrationFormUniqueEmail

class CustomRegistrationFormUniqueEmail(RegistrationFormUniqueEmail):
    first_name = forms.CharField(label=_('First name'), max_length=30,required=True)
    last_name = forms.CharField(label=_('Last name'), max_length=30, required=True)
    def save(self, profile_callback=None):
        new_user = super(CustomRegistrationFormUniqueEmail, self).save(profile_callback=profile_callback)
        new_user.first_name = self.cleaned_data['first_name']
        new_user.last_name = self.cleaned_data['last_name']
        return new_user

then changing view

#       form = form_class(data=request.POST, files=request.FILES)
        form = CustomRegistrationFormUniqueEmail(data=request.POST, files=request.FILES)

but still I am seeing default view containg four fields only ..

help is needed

Praveen

unread,
May 29, 2010, 11:39:01 AM5/29/10
to Django users
Hi Pankaj
here you may refer my blog where i explain how you may extend some
fields while registration.

http://praveensunsetpoint.wordpress.com/category/django/django-registration-profile/

Praveen

On May 29, 4:41 pm, Pankaj Singh <singh.pankaj.iitkg...@gmail.com>
wrote:

shacker

unread,
May 29, 2010, 12:07:51 PM5/29/10
to Django users

Pankaj Singh

unread,
May 31, 2010, 4:07:44 AM5/31/10
to django...@googlegroups.com
I am using django-profiles with django-registration as per tutorial from

http://praveensunsetpoint.wordpress.com/2009/04/21/django-registration-and-django-profile

But after the submitting the form I am getting this error

AttributeError at /accounts/register/

'RegistrationForm' object has no attribute 'save'

Please help me

#################################################################################

def register(request, success_url=None,form_class=RegistrationFormUniqueEmail, profile_callback=None,
    template_name='registration/registration_form.html',
    extra_context=None):
    pform_class = utils.get_profile_form()
 
 
    if request.method == 'POST':
        profileform = pform_class(data=request.POST, files=request.FILES)
        form = form_class(data=request.POST, files=request.FILES)
 
        if form.is_valid():
            new_user = form.save()
            profile_obj = profileform.save(commit=False)
            profile_obj.user = new_user
            profile_obj.save()
 
            return HttpResponseRedirect('/accounts/register/complete/')
 
    else:
        form = form_class()
        profileform = pform_class()
 
    if extra_context is None:
        extra_context = {}
        context = RequestContext(request)
 
        for key, value in extra_context.items():
            context[key] = callable(value) and value() or value
 
    return render_to_response(template_name,{'form': form,'profileform':profileform,}, context_instance=context)
 
####################################################################################

shacker

unread,
May 31, 2010, 12:38:58 PM5/31/10
to Django users
Pankaj -

The fact that you're using a save() method here means that you're
using instructions referring to an older version of django-
registration. But you're probably actually deploying a current
version, which doesn't allow for that. The upgrade guide says:

"Previously, the form used to collect data during registration was
expected to implement a save() method which would create the new user
account. This is no longer the case; creating the account is handled
by the backend, and so any custom logic should be moved into a custom
backend, or by connecting listeners to the signals sent during the
registration process."

Details:

http://stackoverflow.com/questions/2601487/django-registration-django-profile-using-your-own-custom-form/2687377#2687377

Scot


On May 31, 1:07 am, Pankaj Singh <singh.pankaj.iitkg...@gmail.com>
wrote:
> I am using django-profiles with django-registration as per tutorial from
>
> http://praveensunsetpoint.wordpress.com/2009/04/21/django-registratio...

Pankaj Singh

unread,
May 31, 2010, 4:32:14 PM5/31/10
to django-users
Thanks my problem has been resolved :)

gin tonic

unread,
Jun 1, 2010, 12:19:17 PM6/1/10
to Django users
I'm following the praveen tutorial as well but I'm receiving the
error:

"SiteProfileNotAvailable at /accounts/register/"

What am I missing here.

On May 31, 1:32 pm, Pankaj Singh <singh.pankaj.iitkg...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages