Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. def save(self, *args, **kwargs):
  2. user_id = self.id
  3. super(User, self).save(*args, **kwargs)
  4. if user_id is None:
  5. as_A = A(user=self)
  6. as_A.save()
  7. as_B = B(user=self)
  8. as_B.save()
  9.  
  10. class A(models.Model):
  11. user = models.OneToOneField(User, on_delete=models.CASCADE)
  12. x = models.CharField(max_length=100, blank=True)
  13.  
  14. class B(models.Model):
  15. user = models.OneToOneField(User, on_delete=models.CASCADE)
  16. y = models.CharField(max_length=100, blank=True)
  17.  
  18. class RegistrationForm(forms.ModelForm):
  19. password = forms.CharField(
  20. strip=False,
  21. widget=forms.PasswordInput,
  22. )
  23. confirm_password = forms.CharField(
  24. strip=False,
  25. widget=forms.PasswordInput
  26. )
  27.  
  28. class Meta:
  29. model = User
  30. fields = ['email', 'first_name', 'password']
  31.  
  32. def clean(self):
  33. cleaned_data = super(RegistrationForm, self).clean()
  34. password = cleaned_data.get("password")
  35. confirm_password = cleaned_data.get("confirm_password")
  36. if password != confirm_password:
  37. raise forms.ValidationError("Passwords are not same")
  38. return cleaned_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement