Dynamic sitetree and Django 1.7+
wengole opened this issue · 5 comments
I might be missing something, but I am unable to make a dynamic sitetree.
I have a custom SitetreeItem model, and this seems to prevent calling item() at Django load time as it throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Full traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/srv/nasman/snapshots/models.py", line 13, in <module>
File "/usr/local/lib/python3.4/site-packages/sitetree/sitetreeapp.py", line 30, in <module>
MODEL_TREE_CLASS = get_tree_model()
File "/usr/local/lib/python3.4/site-packages/sitetree/utils.py", line 168, in get_tree_model
return get_model_class('MODEL_TREE')
File "/usr/local/lib/python3.4/site-packages/sitetree/utils.py", line 156, in get_model_class
model = apps_get_model(app_name, model_name)
File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 199, in get_model
self.check_models_ready()
File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I tried adding an apps.py inside my app and making use of the ready() method to create the sitetrees. This seemed sensible given the new app loading framework established in Django 1.7
https://docs.djangoproject.com/en/1.8/ref/applications/#methods
Let me know if you need anything further on this.
I believe you could possibly make use of this in utils.py
https://docs.djangoproject.com/en/1.8/ref/applications/#django.apps.apps.get_model
EDIT: Nevermind I see that is what you're using.
I had the same issue: when trying to override sitetree models (Django 1.7 and Django 1.8)
Sorry, I've missed this issue.
I'll try to solve that out this week.
Probably the best way is to define dynamic trees in urls.py
(or even better in a separate module imported by urls.py). I've updated docs accordingly, give it a try.
Closing this. Feel free to reopen if needed.