i have the following task:
from __future__ import absolute_importfrom myproject.celery import appfrom 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: Requested settingDEFAULT_INDEX_TABLESPACE, but settings are not configured. You musteither define the environment variable DJANGO_SETTINGS_MODULE or callsettings.configure() before accessing settings.
If I take out the entity import every thing is fine and no error occurs. When add back :
from myapp.models import Entity
the error returns.
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_tagsclass 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 do I import a django model into a celery task?