Before any explanations, here is the tree of my project
| projectname
|____|__init__.py
|____|celery.py
|____|settings.py
|____|urls.py
|____|wsgi.py
|app1
|app2
Here's my celery.py
from celery import Celery
from celery import shared_task
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')
app = Celery('projectname')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
from app1.models import *
@share_task
def tasks():
''' '''
Every time I try importing models
to the celery.py
file with this line from app1.models import *
I got:
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
And the local server stops working all of a sudden. This post is related to a similar problem, but not sure it's the case here.
What I want is to import some models to the file, so I can use them for some queries.
I got a little clue about what can be wrong, but not sure.
views
import stuff from models.py
views
import stuff from celery.py
like the task to be executed
celery.py
tries to import stuff from models
.
So that circle like a snake that bites its own tail is weird to me.