ubernostrum / django-registration

An extensible user-registration app for Django.
BSD 3-Clause "New" or "Revised" License
923 stars 241 forks source link

Impossible to use RegistrationForm with custom User #150

Closed gmonnerat closed 6 years ago

gmonnerat commented 6 years ago

I have simple and custom User model

models.py

from django.contrib.auth.models import AbstractUser

class Customer(AbstractUser):
  email = models.EmailField(
    verbose_name='email address',
    max_length=55,
    unique=True,
    error_messages={
       'unique': _("A user with that email already exists."),
    },
  )

In settings, I have AUTH_USER_MODEL = "core.Customer"

But in my tests when I try to create an user through reverse("registration_register"), I have the issue bellow:

AttributeError: Manager isn't available; 'auth.User' has been swapped for 'core.Customer'

Checking the code, I found that RegistrationForm.Meta.Model is auth.User instead of core.Customer.

So, to fix I just set User(comes from get_user_model()) explicitly:

--- forms.py    2018-05-17 20:26:47.128525024 +0000
+++ forms.py        2018-05-17 20:26:32.258504105 +0000
@@ -55,7 +55,6 @@
             'password1',
             'password2'
         ]
-        model = User
         required_css_class = 'required'

     def clean(self):

Am I missing something?

ubernostrum commented 6 years ago

https://django-registration.readthedocs.io/en/2.4.1/custom-user.html#overview