'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.
Solution 1:[1]
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:

Solution 2:[2]
There is a better way to resolve this problem
When you enable the Django support in PyCharm it automatically detects that this is a model and objects refers to the Model manager
Instead you can specify that in your models.py itself, which is the preferred method and the best way to code
update your code like
class Foo(models.Model):
// column definitions
objects = models.Manager()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dev.doc |
| Solution 2 |
