Stats Student
unread,Mar 7, 2021, 5:41:15 PM3/7/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-res...@googlegroups.com
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.