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 clean_cache(): from django.db.models.loading import AppCache cache = AppCache() from django.utils.datastructures import SortedDict cache.app_store = SortedDict() cache.app_models = SortedDict() cache.app_errors = {} cache.handled = {} cache.loaded = False
def _redo_app_cache(self): """ Used to repopulate AppCache after fiddling with INSTALLED_APPS. """ a = AppCache() a.loaded = False a.handled = {} a.postponed = [] a.app_store = SortedDict() a.app_models = SortedDict() a.app_errors = {} a._populate()
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 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