0

I have a custom User Model that extends from Django's User and I want to register that user model instead of only the default one.

For this, I am using the ACCOUNT_SIGNUP_FORM_CLASS setting as per allauth doc.

This is what I have in settings.py:

ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.SignupForm' 

And in myapp/forms.py:

class SignupForm(UserCreationForm): class Meta(UserCreationForm.Meta): model = MyUser def signup(self, request, user): print('test') user.save() MyUser(user=user).save() 

The signup() function should be executed:

This class [SignupForm] should implement a def signup(self, request, user) method, where user represents the newly signed up user.

But it isn't (test is not printed). Only User is saved, MyUser isn't. What am I doing wrong?

0

1 Answer 1

1

You are mixing 2 things here:

  1. You're using ACCOUNT_SIGNUP_FORM_CLASS in order to tell all-auth what custom signup form to use
  2. Your custom signup form is inheriting from django's own UserCreationForm

In this way signup() method will never be invoke.

If you have a look at this line you'll see that there's the place where the signup() method is invoked. So, if you want to fully leverage all-auth's built-in forms, I'd recommend you inherit SignupForm from all-auth library.

Yet again, judging by your approach, you might wanna consider setting AUTH_USER_MODEL=MyUser.

Sign up to request clarification or add additional context in comments.

1 Comment

The AUTH_USER_MODEL approach worked after a bit of tweaking. Thank you so much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.