Querying works on shell but not on the Django program code

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Querying works on shell but not on the Django program code

Solomon Mbak
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. 

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

IMG_20190709_190043.jpg (1M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Querying works on shell but not on the Django program code

Anil Khatri
Same for me. But it is working fine.

On Wed, Jul 10, 2019 at 4:56 PM Solomon Mbak <[hidden email]> wrote:
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. 

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAEe3PRUsSkmLrt2zfE%3Df%3DnvbT2kJKcv4MFNJjKy4rgYLV6KQfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Querying works on shell but not on the Django program code

Daniel Roseman-2
In reply to this post by Solomon Mbak
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/37969fcd-ca0d-4fbd-bb57-ffd23f94556d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Querying works on shell but not on the Django program code

Olivier Dugast
In reply to this post by Solomon Mbak


Le mercredi 10 juillet 2019 13:26:53 UTC+2, Solomon Mbak a écrit :
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. 


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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6c92eb57-f5c3-4889-b41c-34d8f0ff3123%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Querying works on shell but not on the Django program code

Olivier Dugast
In reply to this post by Solomon Mbak
sorry, I forgot the brackets. The correct code is:  trick = models.Manage()

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ae2dff0b-3ab9-4d25-9908-131fdc304642%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Querying works on shell but not on the Django program code

Shashikant Sharma
In reply to this post by Olivier Dugast

On Tue, 22 Oct 2019, 21:02 Olivier Dugast, <[hidden email]> wrote:


Le mercredi 10 juillet 2019 13:26:53 UTC+2, Solomon Mbak a écrit :
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. 


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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6c92eb57-f5c3-4889-b41c-34d8f0ff3123%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAB5F1iVEnj1uoskfanBrMq9MWziUer00NXrbVBuUQX7Wyfxf8w%40mail.gmail.com.