Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class forms
- from django import forms
- from django.contrib.auth.models import User
- from django.contrib.auth.forms import UserCreationForm
- from accounts.models import UserProfile
- class RegistrationForm (UserCreationForm):
- email = forms.EmailField(required = True)
- class Meta:
- model = User
- fields = ('username',
- 'first_name',
- 'last_name',
- 'email',
- 'password1',
- 'password2'
- )
- def save (self, commit= True):
- user = super(RegistrationForm,self).save(commit=True)
- user.first_name = self.cleaned_data['first_name']
- user.last_name = self.cleaned_data['last_name']
- user.email = self.cleaned_data['email']
- # user.set_password(self.cleaned_data["password1"])
- if commit:
- user.save()
- return user
- class RegistrationFormFull (UserCreationForm):
- class Meta:
- model = UserProfile
- fields = ('city',
- 'discription',
- 'phone'
- )
- //class views
- from django.shortcuts import render
- from django.shortcuts import redirect
- from welcome.form import RegistrationForm,RegistrationFormFull
- from django.contrib.auth.decorators import login_required
- from django.db import transaction
- from accounts.models import UserProfile
- from django.contrib.auth.models import User
- def register (request) :
- if request.method == 'POST':
- user_form = RegistrationForm(request.POST,instance=request.User)
- full_form =
- RegistrationFormFull(request.POST,instance=request.User.UserProfile)
- if user_form.is_valid() and full_form.is_valid():
- user_form.save()
- full_form.save()
- return redirect('/home')
- else:
- user_form = RegistrationForm(instance=request.user)
- full_form = RegistrationFormFull(instance=request.UserProfile)
- args = {'user_form':user_form,
- 'full_form':full_form
- }
- return render(request,'welcome/reg_form.html',args)
Add Comment
Please, Sign In to add comment