'I am trying to set a user from my custom django signup form based on what option they select from a RadioButton
My forms.py
users = [ ('client', 'Client'), ('customer', 'Customer'), ]
class CustomSignUpForm(SignupForm):
Register_as = forms.ChoiceField(choices=users, widget=forms.RadioSelect)
def save(self, request):
if CustomSignUpForm.Register_as.widget == 'client':
user = super(CustomSignUpForm, self).save(request)
user.is_client = True
user.save()
return user
if CustomSignUpForm.Register_as.widget == 'customer':
user = super(CustomSignUpForm, self).save(request)
user.is_customer = True
user.save()
return user
But after running the code, i get this error
AttributeError at /accounts/signup/ type object 'CustomSignUpForm' has no attribute 'Register_as'
Request Method: POST
Request URL: http://localhost:8000/accounts/signup/
Django Version: 3.2.5
Exception Type: AttributeError
Exception Value:type object 'CustomSignUpForm' has no attribute 'Register_as'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
