Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to solve unresolve attribute reference objects in pyCharm

I’m new to django and I was following a certain tutorial on it using the community Edition of pyCharm but I got this error that says unresolved attribute reference objects for class Product. I haven’t missed any steps from the tutorial I followed but I don’t really know why I’m getting the error. Please I need help on how to solve it. The error is actually from that place that I have Product.objects().all

views.py
from django.shortcuts import render
from django.http import HttpResponse
from products.models import Product


def index(request):
    products = Product.objects().all
    return render(request,'index.html',{'products':products})


def new(request):
    return HttpResponse('New Products')


models.py
from django.db import models


class Product(models.Model):
    name = models.CharField(max_length=255)
    price = models.FloatField()
    stock = models.IntegerField()
    image_url = models.CharField(max_length=2083)


class Offer(models.Model):
    code = models.CharField(max_length=10)
    description = models.CharField(max_length=225)
    discount = models.FloatField()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The community edition doesn’t have the specific Django support that would enable Code insight support for Django ORM.

You’ll just have to live with the fact that objects looks like it’s undefined, or maybe as a band-aid give PyCharm an annotation hint:

class Product(models.Model):
    name = models.CharField(max_length=255)
    price = models.FloatField()
    stock = models.IntegerField()
    image_url = models.CharField(max_length=2083)

    objects: Manager  # <- this annotation
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading