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 :
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