Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #code for admin.py
- from django.contrib.auth.models import User
- from django.contrib import admin
- from models import UserProfile
- admin.site.unregister(User)
- class UserProfileInline(admin.StackedInline):
- model = UserProfile
- class UserProfileAdmin(admin.ModelAdmin):
- inlines = [ UserProfileInline, ]
- admin.site.register(User, UserProfileAdmin)
- #code for form.py
- from django import forms
- from django.forms import ModelForm
- from registration.forms import RegistrationForm
- from django.utils.translation import ugettext_lazy as _
- from models import UserProfile
- #from register.models import
- from django.contrib.auth.models import User
- class UserRegistrationForm(RegistrationForm):
- GENDER_CHOICES = (
- ('M','Male'),
- ('F','Female'),
- )
- first_name = forms.CharField(label=_('First Name'), max_length=30, required=True)
- last_name = forms.CharField(label=_('Last Name'), max_length=30)
- gender = forms.CharField(label = _('Gender'), max_length=10)# choices = GENDER_CHOICES)
- dob = forms.DateField(
- ('%d/%m/%Y',),
- label=_('Date of Birth'),
- widget=forms.DateTimeInput(format = '%d/%m/%Y',attrs={ 'class':'input', 'readonly':'readonly', 'size':'15'}
- )
- )
- city = forms.CharField(max_length=100, label=_('City'))
- class Meta:
- models = UserProfile
- #code for model.py
- from django.db import models
- from django.utils.translation import ugettext_lazy as _
- from django.contrib.auth.models import User, Group
- class UserProfile(models.Model):
- GENDER_CHOICES=(
- ('M', 'Male'),
- ('F','Female'),
- )
- user = models.OneToOneField(User)
- gender = models.CharField(_('Gender'), max_length=1, choices=GENDER_CHOICES, null=False)
- dob = models.DateField(_('Date of Birth'), null=False)
- city = models.CharField(_('City'), max_length=100, null=False)
- #code for regbackend.py
- from django.contrib.auth.models import User
- from forms import UserRegistrationForm
- from models import UserProfile
- def user_created(sender, user, request, **kwargs):
- form = UserRegistrationForm(request.post)
- user_data = User(user=user)
- user_data.first_name = form.data['first_name']
- user_data.last_name = form.data['last_name']
- user_data.save()
- data = UserProfile(user=user)
- data.gender = form.data['gender']
- data.dob = form.data['dob']
- data.user_type = form.data['user_type']
- data.city = form.data['city']
- data.save()
- from registration.signals import user_registered
- user_registered.connect(user_created, sender = UserProfile)
- #code for urls.py
- from django.conf.urls import patterns, include, url
- from django.contrib import admin
- from forms import UserRegistrationForm
- #from registration.views import register
- #import registration.backends.default.urls as regUrls
- #import regbackend
- urlpatterns = patterns('',
- url(r'^accounts/register/$', register, {'backend': 'registration.backends.default.DefaultBackend','form_class': UserRegistrationForm}, 'registration_register'),
- (r'^accounts/', include(regUrls)),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement