Open ErickGSJ opened 5 years ago
The error you're encountering ("Models aren't loaded yet") typically occurs when you're trying to access Django models before they have been fully loaded. In your provided example, the issue might be due to the order in which the Django app is being loaded.
To address this issue, you can make use of the AppConfig.ready()
method to ensure that your code is executed after the models have been loaded. Here's how you can modify your code to avoid this error:
myshop
app, create an apps.py
file (if it doesn't already exist):# myshop/apps.py
from django.apps import AppConfig
class MyShopConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myshop'
def ready(self):
# Import and register your plugin here
from cms.plugin_pool import plugin_pool
from shop.cascade.plugin_base import ShopPluginBase
class MySnippetPlugin(ShopPluginBase):
name = "My Snippet"
render_template = 'myshop/cascade/my-snippet.html'
plugin_pool.register_plugin(MySnippetPlugin)
settings.py
, point to your custom AppConfig
:# settings.py
# ...
INSTALLED_APPS = [
# ...
'myshop.apps.MyShopConfig', # Point to your AppConfig
# ...
]
# ...
By using the AppConfig.ready()
method, you can ensure that your plugin registration code is executed at the appropriate time, after the models have been loaded. This should help you avoid the "Models aren't loaded yet" error.
Remember to replace 'myshop'
with the actual name of your Django app, and adjust the paths accordingly based on your project's structure.
Hi
I import ShopPluginBase from shop.cascade.plugin_base in my project, but failed cause "django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet."
I used the django-shop example as below: myshop/cascade.py
settings.py
myshop/cascade/my-snippet.html
Thanks in advance