Skip to content

Commit

Permalink
Update for models referenced as strings. Refs #272
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Jul 22, 2020
1 parent d03555b commit a8a8302
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Usage

Ensure ``pylint-django`` is installed and on your path and then execute::

pylint --load-plugins pylint_django [..other options..] <path_to_your_sources>
DJANGO_SETTINGS_MODULE=your.app.settings pylint --load-plugins pylint_django [..other options..] <path_to_your_sources>


Prospector
Expand All @@ -70,6 +70,9 @@ Features
* Validates ``Model.__unicode__`` methods.
* ``Meta`` informational classes on forms and models do not generate errors.
* Flags dangerous use of the exclude attribute in ModelForm.Meta.
- Uses Django's internal machinery to try and resolve models referenced as
strings in ForeignKey fields. That relies on ``django.setup()`` which needs
the appropriate project settings defined!


Additional plugins
Expand All @@ -92,23 +95,6 @@ This plugin is disabled by default! To enable it::
pylint --load-plugins pylint_django --load-plugins pylint_django.checkers.migrations


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. 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

0 comments on commit a8a8302

Please sign in to comment.