#19353: Make it easier to extend UserCreationForm for custom user models
-------------------------------------+-------------------------------------
     Reporter:  bmispelon            |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  contrib.auth         |                  Version:
                                     |  1.5-alpha-1
     Severity:  Normal               |               Resolution:
     Keywords:  UserCreationForm     |             Triage Stage:  Accepted
  AUTH_USER_MODEL                    |
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by berkerpeksag):

 Since 849538d03df21b69f0754a38ee4ec5f48fa02c52 has been committed, I think
 `UserCreationForm` works well with subclasses of `AbstractUser`. Here is a
 test case:

 {{{
 diff --git a/tests/auth_tests/test_forms.py
 b/tests/auth_tests/test_forms.py
 index aa0a6af..68a1b88 100644
 --- a/tests/auth_tests/test_forms.py
 +++ b/tests/auth_tests/test_forms.py
 @@ -10,6 +10,7 @@ from django.contrib.auth.forms import (
      SetPasswordForm, UserChangeForm, UserCreationForm,
  )
  from django.contrib.auth.models import User
 +from django.contrib.auth.tests.custom_user import ExtensionUser
  from django.contrib.sites.models import Site
  from django.core import mail
  from django.core.mail import EmailMultiAlternatives
 @@ -153,6 +154,20 @@ class UserCreationFormTest(TestDataMixin, TestCase):
              form['password2'].errors
          )

 +    def test_custom_form(self):
 +        class CustomUserCreationForm(UserCreationForm):
 +            class Meta(UserCreationForm.Meta):
 +                model = ExtensionUser
 +                fields = UserCreationForm.Meta.fields +
 ('date_of_birth',)
 +
 +        data = {
 +            'username': 'testclient',
 +            'password1': 'testclient',
 +            'password2': 'testclient',
 +            'date_of_birth': '1988-02-24',
 +        }
 +        form = CustomUserCreationForm(data)
 +        self.assertTrue(form.is_valid())

  @override_settings(USE_TZ=False,
 PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
  class AuthenticationFormTest(TestDataMixin, TestCase):
 }}}

 I can send this as a PR, if it looks reasonable.

--
Ticket URL: <https://code.djangoproject.com/ticket/19353#comment:16>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.46186d8fd87e94f6011165f782e90eb8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to