This ended up being just a simple Python3 issue, and the solution below
works fine, as far as I can tell so far. I post it here in case anyone
finds it useful:

I defined a "modules checkpoint" to which I can roll back to:

>>> from modules_checkpoint import ModulesCheckpoint
>>> checkpoint = ModulesCheckpoint()
>>> from gramps.webapp.databases.database1 import database
>>> database.dji.Person.all().count()
4
>>> checkpoint.reset()
>>> from gramps.webapp.databases.database2 import database
>>> database.dji.Person.all().count()
0
>>> checkpoint.reset()
>>> from gramps.webapp.databases.database1 import database
>>> database.dji.Person.all().count()
4

(showing the different counts in two different Django databases, defined in
different settings.py). Code is below.

-Doug

# modules_checkpoint.py
import sys
class ModulesCheckpoint(object):
    def __init__(self):
        self.original = sys.modules.copy()

    def reset(self):
        # clear modules:
        for key in list(sys.modules.keys()):
            del(sys.modules[key])
        # load previous:
        for key in self.original:
            sys.modules[key] = self.original[key]


On Mon, May 11, 2015 at 12:17 PM, Doug Blank <doug.bl...@gmail.com> wrote:

> Django users,
>
> We are using Django for two purposes: its ORM for a single-user desktop
> app, and for a regular Django webapp.
>
> For the desktop ORM, is there a way to switch between different
> settings.py? For example, we'd like to be able to load the default
> settings, but then later unload everything, and load different default
> settings.
>
> Looking for something like unloading/reloading all of the relevant
> sys.modules.
>
> We're using python3 if that matters.
>
> Thanks for any suggestions/pointers!
>
> -Doug
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAusYCjbrM%2BWbOrfP0_3uC-QPDXtwMELnFdZLNdABhX97QmYqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to