Skip to content

Commit

Permalink
Document FK-string-reference behavior. Fixes #241
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Aug 6, 2019
1 parent e38768d commit 2df156f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions README.rst
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pylint_django/transforms/foreignkey.py
Expand Up @@ -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')
Expand Down

0 comments on commit 2df156f

Please sign in to comment.