From 2df156fb5bb6a10c51e41f0e3a1c0193891fe1f3 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Tue, 6 Aug 2019 15:15:23 +0300 Subject: [PATCH] Document FK-string-reference behavior. Fixes #241 --- README.rst | 14 ++++++++++---- pylint_django/transforms/foreignkey.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 690ae2f8..cd2d2f43 100644 --- a/README.rst +++ b/README.rst @@ -94,10 +94,16 @@ Known issues If you reference foreign-key models by their name (as string) ``pylint-django`` may not be able to find the model and will report issues because it has no idea what the underlying -type of this field is. If your ``models.py`` itself is not importing the foreign-key class -there's probably some import problem (circular dependencies) preventing referencing the -foreign-key class directly, in which case ``pylint-django`` can't do a huge amount. -If it's just done for convenience that's really up to you the developer to fix. +type of this field is. Supported options are:: + +- ``self`` and ``Model`` - look for this class in the current module which is being examined +- ``app.Model`` - try loading ``app.models`` into the AST parser and look for ``Model`` there + + +If your ``models.py`` itself is not importing the foreign-key class +there's probably some import problem (likely circular dependencies) preventing referencing +the foreign-key class directly. In this case ``pylint-django`` can't do much about it. +We always recommend referencing foreign-key models by their classes. Contributing diff --git a/pylint_django/transforms/foreignkey.py b/pylint_django/transforms/foreignkey.py index 4c4c5656..849a2938 100644 --- a/pylint_django/transforms/foreignkey.py +++ b/pylint_django/transforms/foreignkey.py @@ -63,7 +63,7 @@ def infer_key_classes(node, context=None): break elif isinstance(arg, nodes.Const): try: - # can be 'self , 'Model' or 'app.Model' + # can be 'self' , 'Model' or 'app.Model' if arg.value == 'self': module_name = '' # for relations with `to` first parent be Keyword(arg='to')