Querying works on shell but not on the Django program code

33 views
Skip to first unread message

Solomon Mbak

unread,
Jul 10, 2019, 7:26:53 AM7/10/19
to Django users
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. 
IMG_20190709_190043.jpg

Anil Khatri

unread,
Jul 10, 2019, 7:46:57 AM7/10/19
to django...@googlegroups.com
Same for me. But it is working fine.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc769013-524c-46d9-a08f-2e33d2056b97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Roseman

unread,
Jul 11, 2019, 3:59:32 PM7/11/19
to Django users
I'm not sure why you think that a linting error would stop your code from running. Does it actually work when you run the server? If not, what error do you get then?
--
DR.

Olivier Dugast

unread,
Oct 22, 2019, 11:32:54 AM10/22/19
to Django users
Same for me with a code that comes from a site of initiation to django. In fact it seems that writing Courses.objects.all() is not correct. According to the django doc, you have to add a Manager attribute . I don't really understand why, but it works.
In:
 class Courses(models.Model):
 you add :
  trick = models.Manager
Then in def homepage(request):  you add
cos= Courses.trick.all()

Your error should disappear as it did for my code. 

Sorry if my point is not correct but I used an automatic translator to answer you.

Olivier Dugast

unread,
Oct 22, 2019, 11:48:49 AM10/22/19
to Django users
sorry, I forgot the brackets. The correct code is:  trick = models.Manage()

Shashikant Sharma

unread,
Oct 23, 2019, 9:06:23 AM10/23/19
to django...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages