django allauth custom signup form to assign different groups
django, django-allauth
Solution
signup is the method to override not save.
class LocalSignupForm(forms.Form):
pass
def signup(self, request, user):
role = request.session.get('user_type')
group = role or "Default"
g = Group.objects.get(name=group)
user.groups.add(g)
user.save()
Also the settings has to be
ACCOUNT_SIGNUP_FORM_CLASS = 'useraccount.forms.LocalSignupForm'
Problem
I have two types of users in the system, I want to assign the appropriate group at the time of signing up. Referring to How to customize user profile when using django-allauth, I thought I can override the Signup form and do something like: ``` class CustomSignupForm(forms.Form): login_widget = forms.TextInput(attrs={'type': 'email', 'placeholder': _('email'), 'autofocus': 'autofocus', 'class': 'form-control' }) email = forms.EmailField(label='Email', widget=login_widget) password = PasswordField(label='Password', widget=forms.PasswordInput(attrs={'class': 'form-control'})) password2 = PasswordField(label='Re-type Password', widget=forms.PasswordInput(attrs={'class': 'form-control'})) def save(self, request, user): role = request.GET.get('type') print(role) group = role or "group1" g = Group.objects.get(name=group) user.groups.add(g) user.save() ``` But I keep getting the error below: ``` save() missing 1 required positional argument: 'user' ``` Also, I have configured allauth to use email to login. Thanks for your help.