Since you don't have an answer yet, I'm offering this one, although it's not exactly what you are asking for. I think it might help you anyway, though...
This is how I have done it in a few projects using django-registration 1.0, Python 2.7 and Django 1.6. In this case, I just use username
, email
and password
for sign up and then the user can add profile fields after they have registered. It shouldn't be too tough to modify this to accept the fields upon registration.
I use Twitter Bootstrap for styling, so my templates may or may not help you. I left them out in this case.
I created a couple apps called accounts
and authentication
that hold my models, forms and views:
accounts.models.UserProfile
from django.db import models
class UserProfile(models.Model):
user = models.OneToOneField(User)
title = models.CharField(max_length=100)
company = models.CharField(max_length=250)
authentiction.forms.EditUserProfileForm
from django.forms import ModelForm
class EditUserProfileForm(ModelForm):**
. . .
title = forms.CharField(widget=forms.TextInput())
company = forms.CharField(widget=forms.TextInput())
. . .
accounts.views.EditUserProfileView
from django.views.generic.base import View
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from .models import UserProfile
from .forms import EditUserProfileForm
class EditUserProfileView(View):
form_class = EditUserProfileForm
template_name = 'accounts/profile_edit.html'
@method_decorator(login_required)
def get(self, request, *args, **kwargs):
profile = get_object_or_404(UserProfile, user=request.user)
form_dict = {
'title': profile.title,
'company': profile.company,
}
form = self.form_class(form_dict)
return render(request, self.template_name, {
'form': form,
'profile': profile,
})
@method_decorator(login_required)
def post(self, request, *args, **kwargs):
profile = get_object_or_404(UserProfile, user=request.user)
form = self.form_class(request.POST, instance=profile)
if form.is_valid():
company = form.cleaned_data['company']
title = form.cleaned_data['title']
title.company = title
profile.company = company
# you might need to save user too, depending on what fields
request.user.save()
profile.save()
return HttpResponseRedirect('/dashboard/')
return render(request, self.template_name, {'form': form})
project.urls
url(r'^accounts/profile/edit/', EditUserProfileView.as_view(), name='edit_user_profile_view'),