def index(request):
latest_question_list = Question.objects.all().order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = {'latest_question_list':latest_question_list}
return HttpResponse(template.render(context, request))
The first line of that function gets an error on Question.objects.all()
:
E1101: Class 'Question' has no 'objects' member
I'm following the Django documentation tutorial and they have the same code up and running.
I have tried calling an instance.
Question = new Question()
and using MyModel.objects.all()
Also my models.py
code for that class is this...
class Question(models.Model):
question_text = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def __str__(self):
return self.question_text
To no avail I still have this error.
I have read about pylint and ran this...
pylint --load-plugins pylint_django
Which didn't help, even tho the github readme file says...
Prevents warnings about Django-generated attributes such as Model.objects or Views.request.
I ran the command within my virtualenv, and yet nothing.
So any help would be great.