I have a model called User
that use AbstractUser
and i wanted to submit it to the views that will allow user to create an account and be able to login, but i don’t know how to do that:
models.py:
class User(AbstractUser):
username = models.CharField(max_length=70, unique=True)
email = models.EmailField(unique=True)
phone_number = models.CharField(max_length=15)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'first_name', 'last_name', 'phone_number', 'password']
def __str__(self):
return "{}".format(self.email)
forms.py:
class RegistrationForms(forms.Form):
username = forms.CharField(label="Username", max_length=70,
widget=forms.TextInput(attrs={'class':'form-control'}))
first_name = forms.CharField(label="First Name",
widget=forms.TextInput(attrs={'class':'form-control'}))
last_name = forms.CharField(label="last Name",
widget=forms.TextInput(attrs={'class':'form-control'}))
email = forms.EmailField(label="School Email",
widget=forms.EmailInput(attrs={'class':'form-control'}))
phone_number = PhoneNumberField(label="School Phone Number",
widget=forms.NumberInput(attrs={'class':'form-control'}))
password = forms.CharField(label="Password",
widget=forms.PasswordInput(attrs={'class':'form-control'}))
repeat_password = forms.CharField(label="Repeat Password",
widget=forms.PasswordInput(attrs={'class':'form-control'}))
class Meta:
model = User
fields = ['username', 'password', 'email',
'first_name', 'last_name', 'phone_number',
'repeat_password']
class LoginForm(forms.Form):
email = forms.EmailField(label="School Email",
widget=forms.EmailInput(attrs={'class':'form-control'}))
password = forms.CharField(label="Password",
widget=forms.PasswordInput(attrs={'class':'form-control'}))
class Meta:
model = User
fields = ['email', 'password']