Hello Guys, i found some thread online, and i tried more than once and failed, i think its easy overall but i am still locked :S
Trying to authenticate users with either email or username.
When i say Users i got a custom user, base user + profile with just a few more info about the user submitted through registration form:
class ProfiloUtente(models.Model):
user = models.OneToOneField(User, related_name=‘profile’, on_delete=models.CASCADE)
utente = models.ForeignKey(Utente, on_delete=models.CASCADE)
studio = models.ManyToManyField(Studio)
telefono_fisso = models.CharField(max_length=20, default=None, blank=True)
telefono_mobile = models.CharField(max_length=20, default=None, blank=True)
indirizzo = models.CharField(max_length=40, default=None, blank=True)
citta = models.CharField(max_length=50, default=None, blank=True)
cap = models.CharField(max_length=5, default=None, blank=True)
provincia = models.CharField(max_length=30, default=None, blank=True)
cod_fiscale = models.CharField(max_length=16, default=None, blank=True)
p_iva = models.CharField(max_length=27, default=None, blank=True)
def str(self):
return self.user.username
And this is my data about the default user fields:
class RegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
first_name = forms.CharField(max_length=30, required=True)
last_name = forms.CharField(max_length=100, required=True)
class Meta:
model = User
fields = (
'username',
'email',
'first_name',
'last_name',
'password1',
'password2',
)
…
…
The login form is the django default login with username + psw.
Could someone help me understanding what i could do to extend the field username to also take the email into it?
Thanks