So I recently added an optional user profile model that is linked to a user via a OneToOneField like so:
class UserProfile(models.Model): # Creating class
user = models.OneToOneField(User, on_delete=models.CASCADE)
This worked fine, and my current UserProfile models were intact both before and after I added in this field to link the profile to a user.
The problem comes when I log in on the website as a valid user, after submitting the log in form comes an error:
AttributeError at /login/
'User' object has no attribute 'profile'
I have searched through my files for anything along the lines of 'User.profile
', and similar queries, however I can't seem to find anything that would allow me to properly log in as a user.
I wasn't sure what other code to post here, and didn't want to spam this question with potentially unnecessary code so tell me if there's anything more specific (views.py, models.py, forms.py, etc) that will be needed to solve this sort of problem, or if you know of any possible solutions.
Thank you
You haven't set any related_name attribute on that one-to-one field, so the reverse accessor will be called userprofile
not profile
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With