Hello everyone, new Django developer here.
I’m creating an API with Django Rest Framework where Django-allauth is responsible for SIgnup Form, after everything set up I have the following Register:
However, I want to change the fields on this form and in order to achieve that I wrote the following code:
# settings.py
ACCOUNT_FORMS = {
"signup": "user.forms.SignupForm",
}
# models.py
class User(AbstractBaseUser, PermissionsMixin):
"""Custom user model that supports using email instead of username"""
email = models.EmailField(max_length=255, unique=True)
name = models.CharField(max_length=255)
age = models.IntegerField()
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'email'
def __str__(self):
return self.email
# forms.py
from django import forms
from django.conf import settings
from django.utils.translation import ugettext, ugettext_lazy as _
from allauth.account.forms import SignupForm as BaseSignupForm
class SignupForm(BaseSignupForm):
email = forms.EmailField(
widget=forms.TextInput(
attrs={
'type': 'email',
'placeholder': _('E-mail address')
}
)
)
age = forms.IntegerField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if settings.SIGNUP_EMAIL_ENTER_TWICE:
self.fields["email2"] = forms.EmailField(
label=_("E-mail (again)"),
widget=forms.TextInput(
attrs={
'type': 'email',
'placeholder': _('E-mail address confirmation')
}
)
)
self.fields['email'].label = ugettext("E-mail")
self.fields['email'].required = True
self.fields['age'].label = ugettext("age")
self.fields['age'].required = True
to_remove = [
'username',
'password1',
'password2' # ignored when not present
]
for field in to_remove:
if field in self.fields:
del self.fields[field]
After implementing that, nothing changed on my Signup Form and I’m still getting the same Register in DRF. Am I missing something?
Thank you in advance.
Cheers,
Mário