Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved attribute reference 'objects' for class 'Foo' in PyCharm

Why am I seeing this warning for a class which is a subclass of models.Model (Foo is defined as class Foo(models.Model))? This is wherever I use Foo.objects.filter(...).

Responding to request for more detail with a simplified example:

# ------ models.py ---------
from django.db import models

class Foo(models.Model):
    pass

# ------ views.py ---------
from models import Foo

inquiry = Foo.objects.filter(...)  # PyCharm gives warning for objects here
    ...

PyCharm gives no warnings for the import statements in either file.

like image 991
Mitch Avatar asked Dec 05 '14 03:12

Mitch


1 Answers

Is your pycharm version community or professional? If your pycharm is community, maybe it needs a pluggin to support django. If your pycharm is professional, make sure that in: Preferences > Languages&Frameworks > Django > Enable Django Support the option is chosen. Here is the image:

like image 171
GanQiang Avatar answered Sep 19 '22 01:09

GanQiang