一旦芹菜任务完成,我想更新我的模型对象。不过,我目前不知道如何去做。
这是文件的布局
模型.py
from photos.tasks import photo_download
class Photo(models.Model):
....fields....
@receiver(post_save)
def download_photo_callback(sender, **kwargs):
photo = kwargs["instance"]
result = photo_download.delay(photo.uid)
任务.py
from photo.models import Photo
@task()
def photo_download(photo_uid, callback=None):
...do stuff...
photo.status = 'D'
photo.save()