8

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.

3

2 Answers 2

13

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:

Sign up to request clarification or add additional context in comments.

1 Comment

2021, this is still relevant.
3

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()

1 Comment

is it true pycharm community?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.