问题
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:
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.
来源:https://stackoverflow.com/questions/2677649/how-to-reload-django-models-without-losing-my-locals-in-an-interactive-session