Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过django芹菜的queryset_Django_Django Celery - Fatal编程技术网

如何通过django芹菜的queryset

如何通过django芹菜的queryset,django,django-celery,Django,Django Celery,我正在尝试使用django构建Instagram机器人。我想实现django芹菜来在后台运行任务。我现在面临一些问题 task.py from celery import shared_task from projects.services.instagram_bot import InstagramBot @shared_task def lazy_post_link_1_task(post_url, current_user, bot_id, email, password, time_

我正在尝试使用django构建Instagram机器人。我想实现django芹菜来在后台运行任务。我现在面临一些问题

task.py

from celery import shared_task
from projects.services.instagram_bot import InstagramBot


@shared_task
def lazy_post_link_1_task(post_url, current_user, bot_id, email, password, time_interval, comments):
    instagram_bot = InstagramBot()
    instagram_bot.comment_on_post(post_url, current_user, bot_id, email, password, time_interval, comments)
views.py

for bot in lazy_bots:
    lazy_bot_filter_comments = Comments.objects.all().exclude(botscomment__bot_id=bot.id)[
                                                   :int(no_of_comment_for_lazy_bot)]

    lazy_post_link_1_task.delay(lazy_post_link_1, request.user, bot.id, bot.email, bot.password,
                                                    lazy_bot_time_interval,
                                                    lazy_bot_filter_comments)
我面临着这样的错误


我不知道我的任务是什么

您不能直接将queryset传递给芹菜任务,因为任务参数必须是可序列化的。相反,您可以将对象ID列表传递给任务,然后运行查询
从任务本身。另一个可能的选择是使用Django或更好的,如果您只需要数据,并且准备好使用映射来处理它

不能直接将queryset传递给芹菜任务,因为任务参数必须是可序列化的。相反,您可以将对象ID列表传递给任务,然后运行查询
从任务本身。另一个可能的选择是使用Django或更好的,如果您只需要数据,并且准备好使用映射来处理它

最佳实践是不要将模型实例/查询集传递给芹菜。传递ID和其他信息以在工作端生成此查询

不要将Django模型对象传递给芹菜任务。为了避免模型对象在传递给芹菜任务之前已经更改的情况,请将对象的主键传递给芹菜。当然,在处理对象之前,您必须使用主键从数据库中获取对象


最佳做法是不要将模型实例/查询集传递给芹菜。传递ID和其他信息以在工作端生成此查询

不要将Django模型对象传递给芹菜任务。为了避免模型对象在传递给芹菜任务之前已经更改的情况,请将对象的主键传递给芹菜。当然,在处理对象之前,您必须使用主键从数据库中获取对象