Есть view.py
from rest_framework.response import Response
from rest_framework.views import APIView
from .models import *
from .tasks import trasactiontaskfunc
#from .trasactionfunc import trasactionfunc
# Create your views here.
class PageView(APIView):
def get(self, request, item):
page = Page.objects.filter(pk=item).first()
totrasaction = []
la = []
for e in page.pageaudio_set.all():
el = {
'type': 'audio',
'id': e.audio.pk,
'title': e.audio.title,
'counter': e.audio.counter,
'bitrate': e.audio.bitrate,
}
totrasaction.append(e.audio)
la.append({'order': e.order, 'quantity': e.quantity, 'el': el})
lv = []
for e in page.pagevideo_set.all():
el = {
'type': 'video',
'id': e.video.pk,
'title': e.video.title,
'counter': e.video.counter,
'fileurl': e.video.fileurl,
'subtitresurl': e.video.subtitresurl
}
totrasaction.append(e.video)
lv.append({'order': e.order, 'quantity': e.quantity, 'el': el})
lt = []
for e in page.pagetext_set.all():
el = {
'type': 'text',
'id': e.text.pk,
'title': e.text.title,
'counter': e.text.counter,
'text': e.text.text,
}
totrasaction.append(e.text)
lt.append({'order': e.order, 'quantity': e.quantity, 'el': el})
content = {
"id": item,
"title": page.title,
"pageaudio": la,
"pagevideo": lv,
"pagetext": lt,
}
trasactiontaskfunc.delay(totrasaction)
#trasactionfunc(totrasaction)
return Response({'t':1})
Есть таски:
from celery import shared_task
from api.trasactionfunc import trasactionfunc
@shared_task(time_limit=20000)
def trasactiontaskfunc(totrasaction):
return trasactionfunc(totrasaction)
Транзакция:
from django.db import transaction
def trasactionfunc(totrasaction):
try:
with transaction.atomic():
for e in totrasaction:
e.counter = e.counter + 1
e.save()
except:
transaction.rollback()
else:
return True
return False
Почему получаю ответ :
EncodeError at /api/page/1
is not JSON serializable
Если функция асинхронная и нету return вообще? Если делаю напрямую, без celery то нет никаких ошибок вообще...