Reputation: 75
I'm a complete novice to python and Django.
I have tried several solutions I found on stack overflow, but I still get the same issue. I've tried querying from shell and it works well, but not on my code.
I've installed pylint
using
pip install pylint-django
I have also changed the Linter settings on Settings > User Settings > Python from pyLint
to pylint_django
and also to flake8
, but no positive results.
I still get the message "Class Courses has no 'objects' member pylint(no-member)"
These are my codes from models.py:
class Courses(models.Model):
course_title = models.CharField(max_length=200)
course_image = models.ImageField(upload_to='course_images/')
course_duration = models.TimeField()
def __str__(self):
return self.course_title
The views.py looks like this:
from django.shortcuts import render
from django.http import HttpResponse
from .models import Courses
def homepage(request):
cos = Courses.objects.all()
context={ 'courses': cos }
return render(request, "main/home.html", context)
I need help. I'm completely stuck.
Upvotes: 0
Views: 209
Reputation: 75
It was right under my nose the whole time.
Goto settings > Search for "terminal" > open any of the do "Edit in settings.json"
and add the code below.
"python.linting.pylintArgs": ["--load-plugins=pylint_django"]
NOTE: make sure you add a comma at the end of the last line before adding the code below, else you'd get an error.
Save that and then go back to settings and search for "lint"
check the left hand side of the search and locate Python Configuration
Make sure "The Linter to use" is set either to pyLint
or pylint_django
That should work fine.
Upvotes: 1
Reputation: 2269
That is an error message from the linter, not from library. You need not worry about that. Since the IDE might have default linter settings applied, that might be a cause for this. Also, you can keep singular name for your models as a practice and if you register that model in admin, it automatically gives a s
in the end.
It should like this
from django.db impot models
class Courses(models.Model):
course_title = models.CharField(max_length=200)
course_image = models.ImageField(upload_to='course_images/')
course_duration = models.TimeField()
def __str__(self):
return self.course_title
Upvotes: 1