Skip to content

Commit d00dafb

Browse files
committed
Document FK-string-reference behavior. Fixes #241
1 parent e38768d commit d00dafb

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ Known issues
9494

9595
If you reference foreign-key models by their name (as string) ``pylint-django`` may not be
9696
able to find the model and will report issues because it has no idea what the underlying
97-
type of this field is. If your ``models.py`` itself is not importing the foreign-key class
98-
there's probably some import problem (circular dependencies) preventing referencing the
99-
foreign-key class directly, in which case ``pylint-django`` can't do a huge amount.
100-
If it's just done for convenience that's really up to you the developer to fix.
97+
type of this field is. Supported options are::
98+
99+
- ``self`` and ``Model`` - look for this class in the current module which is being examined
100+
- ``app.Model`` - try loading ``app.models`` into the AST parser and look for ``Model`` there
101+
102+
103+
If your ``models.py`` itself is not importing the foreign-key class
104+
there's probably some import problem (likely circular dependencies) preventing referencing
105+
the foreign-key class directly. In this case ``pylint-django`` can't do much about it.
106+
We always recommend referencing foreign-key models by their classes.
101107

102108

103109
Contributing

pylint_django/transforms/foreignkey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def infer_key_classes(node, context=None):
6363
break
6464
elif isinstance(arg, nodes.Const):
6565
try:
66-
# can be 'self , 'Model' or 'app.Model'
66+
# can be 'self' , 'Model' or 'app.Model'
6767
if arg.value == 'self':
6868
module_name = ''
6969
# for relations with `to` first parent be Keyword(arg='to')

0 commit comments

Comments
 (0)