开发者

django-extensions shell_plus autoload

How do I tell django-extensions' shell_plu开发者_高级运维s what models I want to autoload?


In the past whenever shell_plus wasn't autoloading my models it was normally because there was an error in the models and it was causing the autoloading to fail.

If you open shell plus and then try to manually load your modules one at a time what happens?

from app.models import ModelName

Another thing to try is to turn off all of the apps except for the default django apps in the settings file, and see if they autoload just fine. If they do, then slowly add more and more apps, one at a time, until it stops working, then you can find out which model is having issues. Once you know which model is having issues, it will make it easier to find out what is going on.

The most common error I had was a cyclical dependency between two different models (this model depends on that model, but it wasn't loaded yet, and vice versa).

Hope that helps.


shell_plus – An enhanced version of the Django shell. It will autoload all your models making it easy to work with the ORM right away.

Quote from django-extensions github wiki located https://github.com/django-extensions/django-extensions/wiki/Current-Command-Extensions

Don't believe its actually changeable its designed to quickly autoload ALL models.


I've made a new patch for the shell_plus extension that makes it possible to ignore some models. Waiting for https://github.com/django-extensions/django-extensions/pull/99 to get accepted.


according to the code. shell_plus always loading all your models.


By default shell_plus always loads all your models. Thanks to @xeor you can use the option SHELL_PLUS_DONT_LOAD in your settings to skip some of your models. You can also configure aliases to your models to avoid names collisions.

More details: http://django-extensions.readthedocs.org/en/latest/shell_plus.html?highlight=shell_plus#configuration

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜