Celery raise error while passing my queryset obj as parameter
<p>I trying to execute a periodic task, so I used celery with Django 1.8 and Django Rest Framework and Postgres as Database. When I try to send my obj to the task I get <code>TypeError: foreign_model_obj is not JSON serializable</code>. How can I pass my queryset object to my Task.</p>

<p><strong>views.py :</strong></p>

<pre class="lang-py prettyprint-override"><code>class MyModelCreateApiView(generics.CreateAPIView):
    queryset = MyModel.objects.all()
    serializer_class = MyModelSerializer
    authentication_classes = (TokenAuthentication,)

    def create(self, request, *args, **kwargs):
        data = dict()
        data['foreign_model_id'] = kwargs['pk']
        foreign_model_obj = MyForeignModel.objects.get(id=data['foreign_model_id'])

        obj = MyModel.objects.create(**data)
        result = serialize_query(MyModel, {"id": obj.id})
        local_time = foreign_model_obj.time
        my_celery_task.apply_async([foreign_model_obj], eta=local_time)
        return Response(result)
</code></pre>



<p><strong>tasks.py :</strong></p>

<pre class="lang-py prettyprint-override"><code>@celery_app.task(name="my_celery_task")
def my_first_celery_task(mymodel_obj):
    # ... updating obj attributes
    mymodel_obj.save()
</code></pre>