routers.py 776 B

12345678910111213141516171819202122232425
  1. from rest_framework.routers import Route
  2. from rest_framework_nested import routers
  3. class BulkSimpleRouter(routers.SimpleRouter):
  4. """
  5. Router supports PUT method on list view to support bulk updates
  6. Thanks to Github user thomasWajs
  7. https://github.com/miki725/django-rest-framework-bulk/issues/11#issuecomment-45742375
  8. Fun fact. I, bufke, first opened the question about this in 2014!
  9. """
  10. routes = routers.SimpleRouter.routes
  11. routes[0] = Route(
  12. url=r"^{prefix}{trailing_slash}$",
  13. mapping={
  14. "get": "list",
  15. "post": "create",
  16. "put": "bulk_update",
  17. "delete": "bulk_delete",
  18. },
  19. name="{basename}-list",
  20. detail=False,
  21. initkwargs={"suffix": "List"},
  22. )