Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class Meta:
  2. exclude = ['profile']
  3.  
  4. first_name = forms.CharField(max_length=30)
  5. last_name = forms.CharField(max_length=30)
  6. email = forms.EmailField(max_length=30)
  7. password = forms.CharField(max_length=30)
  8. confirm_password = forms.CharField(max_length=30)
  9.  
  10. def clean(self):
  11. password = self.cleaned_data['password']
  12. confirm_password = self.cleaned_data['confirm_password']
  13. if len(self.cleaned_data['password']) < 6:
  14. raise forms.ValidationError('Password must be at least 6 characters.')
  15. if password != confirm_password:
  16. raise forms.ValidationError('Passwords must match.')
  17. return super(CreateSpecializedProfileAdminForm, self).clean()
  18.  
  19. def save(self, commit=True):
  20. from django.contrib.auth.models import User
  21. first = self.cleaned_data['first_name']
  22. last = self.cleaned_data['last_name']
  23. email = self.cleaned_data['email']
  24. password = self.cleaned_data['password']
  25. user = User.objects.create_user(email, email, password)
  26. user.first_name = first
  27. user.last_name = last
  28. user.save()
  29. profile = UserProfile()
  30. profile.user_auth = user
  31. profile.save()
  32. specialized_profile = SpecializedProfile()
  33. specialized_profile.profile = profile
  34. specialized_profile.save()
  35. return specialized_profile
  36.  
  37. form = CreateSpecializedProfileAdminForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement