I have the following task:
from __future__ import absolute_import from myproject.celery import app from myapp.models import Entity @app.task def add(entity_id): entity = Entity.objects.get(pk=entity_id) return entity.name
I get the following error:
django.core.exceptions.ImproperlyConfigured: the requested setting is DEFAULT_INDEX_TABLESPACE, but the settings are not configured. You must either define the DJANGO_SETTINGS_MODULE environment variable or call settings.configure () before accessing the settings.
If I take out an entity object, all things are beautiful and no errors occur. When adding back:
from myapp.models import Entity
The error is returned.
from __future__ import unicode_literals from django.contrib.auth.models import User from django.db import models from django.core.mail import EmailMultiAlternatives from django.template import Context, loader from django.utils.html import strip_tags class Entity(models.Model): area = models.ForeignKey(Area) name = models.CharField(max_length=255) type = models.CharField(max_length=255) status = models.IntegerField(choices=STATUS_TYPES, default=0) created_at = models.DateTimeField(auto_now_add = True) updated_at = models.DateTimeField(auto_now = True) def __unicode__(self): return self.name
How to import django model into celery task?
source share