Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Meta:
- exclude = ['profile']
- first_name = forms.CharField(max_length=30)
- last_name = forms.CharField(max_length=30)
- email = forms.EmailField(max_length=30)
- password = forms.CharField(max_length=30)
- confirm_password = forms.CharField(max_length=30)
- def clean(self):
- password = self.cleaned_data['password']
- confirm_password = self.cleaned_data['confirm_password']
- if len(self.cleaned_data['password']) < 6:
- raise forms.ValidationError('Password must be at least 6 characters.')
- if password != confirm_password:
- raise forms.ValidationError('Passwords must match.')
- return super(CreateSpecializedProfileAdminForm, self).clean()
- def save(self, commit=True):
- from django.contrib.auth.models import User
- first = self.cleaned_data['first_name']
- last = self.cleaned_data['last_name']
- email = self.cleaned_data['email']
- password = self.cleaned_data['password']
- user = User.objects.create_user(email, email, password)
- user.first_name = first
- user.last_name = last
- user.save()
- profile = UserProfile()
- profile.user_auth = user
- profile.save()
- specialized_profile = SpecializedProfile()
- specialized_profile.profile = profile
- specialized_profile.save()
- return specialized_profile
- form = CreateSpecializedProfileAdminForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement