I got the following error when I created Profile model
Instance of 'OneToOneField' has no 'username' member
This is the snippet of the code I created
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="default.jpg", upload_to="profile_pics")
def __str__(self):
return f"{self.user.username} Profile"
previously it was working fine. Now, all of a sudden I am getting this error.I didn't understand the meaning of this error. How do I solve it? Thank you
In order for pylint to work properly with Django you should install the pylint-django
packege:
pip install pylint-django
Then you can run pylint
with pylint_django
as a plugin:
pylint --load-plugins pylint_django <path_to_django_file>
If you are using VSCode as your IDE, you can add this snippet to your .vscode/settings.json
file to load the plugin for your project:
{
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django"
]
}
Or, if you have a .pylintrc
file, you can add this line to load the plugin:
[MASTER]
load-plugins=pylint_django
You can find out more on about pylint-django
here.
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