I have array objects:
const ordsend =[
{
order: 4,
id: 1,
},
{
order: 2,
id: 2,
}
]
where id is the primary key, That for axios I am sending this by the POST method:
this.axios.post('route-dispatchs/order/', this.ordsend)
.then((response) => {
console.log(success);
});
this seems right to me because through this filtering by the id and updating its respective order
class RouteDispatchViewSet(viewsets.ModelViewSet):
queryset = RouteDispatch.objects.all()
serializer_class = RouteDispatchSerializer
@list_route(methods=['post'], url_path='order')
def order_dispatch(self, request):
for data in request.data:
self.queryset.filter(id=data['id']).update(order=data['order'])
page = self.paginate_queryset(self.queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(self.queryset, many=True)
return Response(serializer.data)
but unfortunately it shows me the following error:
AttributeError: 'list' object has no attribute 'items'
How can I do a multiple update in a single request?
error:
when I send only one :
this.ordsend[0]
and I remove the ** for ** updates perfectly.