How to reload Django models without losing my loca

2019-06-25 13:38发布

I'm doing some research with an interactive shell and using a Django app (shell_plus) for storing data and browsing it using the convenient admin.

Occasionally I add or change some of the app models, and run a syncdb (or South migration when changing a model). The changes to the models don't take effect in my interactive session even if I re-import the app models. Thus I'm forced to restart the shell_plus and lose my precious locals() in the process.

Is there any way to reload the models during a session? Thanks!!

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-25 13:44

You can use this snippet to rebuild the AppCache. Do not forget to remove all *.pyc files if any by using something like:

find . -name "*.pyc" -exec rm {} \;

Otherwise the reload() will ignore your changes in your models.py file.

查看更多
登录 后发表回答