def _reload_models_module(self, app_name): """ Reload Django models Based on http://stackoverflow.com/questions/890924/how-do-you-reload-a-django-model-module-using-the-interactive-interpreter-via-m """ curdir = os.getcwd() cache = AppCache() for app in cache.get_apps(): f = app.__file__ if f.startswith(curdir) and f.endswith('.pyc'): try: os.remove(f) except Exception: pass __import__(app.__name__) reload(app) cache.app_store = SortedDict() cache.app_models = SortedDict() cache.app_errors = {} cache.handled = {} cache.loaded = False # Reset app's models in global scope # Using a dictionary here instead of cache.get_models(app_name) # The latter does not seem to work (look into that) reimported_app = importlib.import_module("{}.models".format(app_name)) model_names = self.model_globals[app_name] for model_name in model_names: self.shell_globals[model_name] = getattr(reimported_app, model_name) self._update_class_instances(reimported_app, model_name)
def reload_django_appcache(): cache = AppCache() cache.app_store = SortedDict() cache.app_models = SortedDict() cache.app_errors = {} cache.handled = {} cache.loaded = False for app in cache.get_apps(): __import__(app.__name__) reload(app)
def handle(self, *args, **options): apps = AppCache() check = [] for module in apps.get_apps(): for d in module.__dict__: ref = getattr(module, d) if isinstance(ref, simpledb.models.ModelMetaclass): domain = ref.Meta.domain.name if domain not in check: check.append(domain) sdb = simpledb.SimpleDB(settings.AWS_KEY, settings.AWS_SECRET) domains = [d.name for d in list(sdb)] for c in check: if c not in domains: sdb.create_domain(c) print "Creating domain %s ..." % c
def reload_models(): import os from django.db.models.loading import AppCache cache = AppCache() curdir = os.getcwd() for app in cache.get_apps(): f = app.__file__ if f.startswith(curdir) and f.endswith('.pyc'): os.remove(f) __import__(app.__name__) reload(app) from django.utils.datastructures import SortedDict cache.app_store = SortedDict() cache.app_models = SortedDict() cache.app_errors = {} cache.handled = {} cache.loaded = False
from django.db.models.loading import AppCache cache = AppCache() for app in cache.get_apps(): __import__(app.__name__) reload(app) from django.utils.datastructures import SortedDict cache.app_store = SortedDict() cache.app_models = SortedDict() cache.app_errors = {} cache.handled = {} cache.loaded = False