Как указать пакету django-registration использовать кастомную форму регистрации?
Я делаю регистрацию и авторизацию пользователя с помощью пакета django-registration
. Мне нужно было сделать так, чтобы емейлы у пользователей были уникальными и поэтому я сделал кастомную модель пользователя, переопределив только поле емейла:
class User(AbstractUser):
email = models.EmailField(
_('email address'),
unique=True,
)
В настройках я соответственно указал эту модель:
AUTH_USER_MODEL = 'shop.User'
Теперь, когда я хочу зайти на страницу регистрации, у меня возникает такая ошибка:
_ImproperlyConfigured at /accounts/register/
You are attempting to use the registration view <class 'django_registration.backends.activation.views.RegistrationView'>
with the form class <class 'django_registration.forms.RegistrationForm'>,
but the model used by that form (<class 'django.contrib.auth.models.User'>) is not
your Django installation's user model (<class 'shop.models.User'>).
Most often this occurs because you are using a custom user model, but
forgot to specify a custom registration form class for it. Specifying
a custom registration form class is required when using a custom user
model. Please see django-registration's documentation on custom user
models for more details._
Она говорит, что модель в классе Meta
формы RegistrationForm
и модель, прописанная в настройках, различны.
Чтобы решить данную проблему, я решил переопределить RegistrationForm
:
CustomUser = get_user_model()
class CustomRegistrationForm(RegistrationForm):
class Meta(RegistrationForm.Meta):
model = CustomUser
Но теперь я не знаю, как мне указать чтобы django-registration
использовал эту форму для регистрации пользователей.