4

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

GJ.
  • 5,226
  • 13
  • 59
  • 82

1 Answers1

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.

Community
  • 1
  • 1
Reto Aebersold
  • 16,306
  • 5
  • 55
  • 74
  • I deleted the *.pyc files and ran the snippet -- I see the models.pyc get created as soon as I run the snippet (none of the other pyc files get created at this point) but the model *still* doesn't get updated. (AttributeError when trying to access a newly added field) Any idea what could be wrong? – GJ. Apr 20 '10 at 19:51
  • I tried it using an ipython shell. Did you re-import your model classes after running the snippet? – Reto Aebersold Apr 20 '10 at 20:09
  • Yes I did, still can't access the new attribute. – GJ. Apr 21 '10 at 07:30
  • I did it like this: Add new field to model -> run syncdb -> clear pyc files -> run snippet -> re-import updated model -> create a new instance of the model -> access to newly added field Maybe you can install ipython an try again. And you have to create new instances of the updated model I think. – Reto Aebersold Apr 21 '10 at 08:26