Hi, I have a ModelViewSet implementation which is routed through the
DefaultRouter and everything works fine.

router = routers.DefaultRouter()
router.register(r'item', views.ItemViewSet, 'item')

class ItemViewSet(viewsets.ModelViewSet):
     serializer_class = ItemSerializer

I would now like to add more methods to this setup by which the caller
can submit a POST request with a list of items to update, e.g. [ {
"id": 1, "prop": 1 } , { "id": 2, "prop": 4} ]
And I would like this method to be accessible through the [
/api/item/update_prop/ ] endpoint.

Currently, I am doing this by declaring a new class which inherits
from APIView and manually add a URL mapping to [
/api/item_update_prop/ ] which I do not particularly like.

I tried doing it through @action(detail=False, methods=['post']) but
kept getting an error that the method expects a dictionary that the
serializer needs to parse, but is receiving a list instead.

Thanks for any insight on how to best do this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAMZO7wL-GFHw_gpuQWG_8wUoSbCjnQubQCF3WLSNRR0oqQ9wMw%40mail.gmail.com.

Reply via email to