pylint-django icon indicating copy to clipboard operation
pylint-django copied to clipboard

Instance of 'ManyToManyField' has no 'all' memberPylint E1101:(no-member)

Open LCH-1 opened this issue 2 years ago • 7 comments

models.py

from django.db import models


class Category(models.Model):
    name = models.CharField("name", max_length=100)


class Movie(models.Model):
    categories = models.ManyToManyField(Category, related_name="movies")
    created_at = models.DateTimeField("created_at", auto_now_add=True)

    def __str__(self):
        test = ""  # for just test
        return ""

    def get_categories(self):
        return self.categories.all()

    def get_created_date(self):
        return self.created_at.strftime("%Y-%m-%d")

pylint extention result

2023-09-13 18:33:10.721 [info] [Trace - 6:33:10 PM] Sending notification 'textDocument/didSave'.
2023-09-13 18:33:10.725 [info] [Trace - 6:33:10 PM] Received notification 'window/logMessage'.
2023-09-13 18:33:10.725 [info] c:\Users\user\Desktop\django_test\venv\Scripts\python.exe -m pylint --reports=n --output-format=json --disable=C0115, C0114, C0116 --load-plugins=pylint_django --django-settings-module=test_project.settings --clear-cache-post-run=y --from-stdin c:\Users\user\Desktop\django_test\testapp\models.py
2023-09-13 18:33:10.725 [info] [Trace - 6:33:10 PM] Received notification 'window/logMessage'.
2023-09-13 18:33:10.725 [info] CWD Linter: c:\Users\user\Desktop\django_test
2023-09-13 18:33:12.273 [info] [Trace - 6:33:12 PM] Received notification 'window/logMessage'.
2023-09-13 18:33:12.273 [info] file:///c%3A/Users/user/Desktop/django_test/testapp/models.py :
[
    {
        ...
        "type": "warning",
        "obj": "Movie.__str__",
        "symbol": "unused-variable",
        "message": "Unused variable 'test'",
        "message-id": "W0612"
    },
    {
        ...
        "type": "error",
        "obj": "Movie.get_categories",
        "symbol": "no-member",
        "message": "Instance of 'ManyToManyField' has no 'all' member",
        "message-id": "E1101"
    },
    {
        ...
        "type": "error",
        "obj": "Movie.get_created_date",
        "symbol": "no-member",
        "message": "Instance of 'DateTimeField' has no 'strftime' member",
        "message-id": "E1101"
    }
]

pylint terminal result

c:\Users\user\Desktop\django_test\venv\Scripts\python.exe -m pylint --reports=n --output-format=json --disable="C0115, C0114, C0116" --load-plugins=pylint_django --django-settings-module=test_project.settings --clear-cache-post-run=y c:\Users\user\Desktop\django_test\testapp\models.py

[
    {
        ...
        "type": "warning",
        "obj": "Movie.__str__",
        "symbol": "unused-variable",
        "message": "Unused variable 'test'",
        "message-id": "W0612"
    }
]

versions

Pylint(Vscode Extention) v2023.6.0
Python 3.11.1
Django==4.2.4
pylint==2.17.5
pylint-django==2.5.3
astroid==2.15.6

LCH-1 avatar Sep 13 '23 07:09 LCH-1