Django - Executing a task through celery from a model

后端 未结 3 1389
时光取名叫无心
时光取名叫无心 2021-02-06 03:50

In my models.py:

from django.db import models
from core import tasks

class Image(models.Model):
    image     = models.ImageField(upload_to=\'images/orig\')
            


        
3条回答
  •  我在风中等你
    2021-02-06 04:44

    i wonder if the problem might be a circular import (models and tasks importing each other at the top level). try moving "from core.models import Image" into create_thumbnail, i.e. changing tasks to

    from celery.decorators import task
    
    @task()
    def create_thumbnail(image_id):
        from core.models import Image
        ImageObj = Image.objects.get(id=image_id)
        # other stuff here
    

提交回复
热议问题