views:

143

answers:

1

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  A: 

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.

aeby
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
I tried it using an ipython shell. Did you re-import your model classes after running the snippet?
aeby
Yes I did, still can't access the new attribute.
Gj
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 fieldMaybe you can install ipython an try again. And you have to create new instances of the updated model I think.
aeby