apirouter.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from rest_framework.routers import (
  2. DefaultRouter, Route, DynamicDetailRoute, DynamicListRoute)
  3. class MisagoApiRouter(DefaultRouter):
  4. include_root_view = False
  5. include_format_suffixes = False
  6. routes = [
  7. # List route.
  8. Route(
  9. url=r'^{prefix}{trailing_slash}$',
  10. mapping={
  11. 'get': 'list',
  12. 'post': 'create'
  13. },
  14. name='{basename}-list',
  15. initkwargs={'suffix': 'List'}
  16. ),
  17. # Dynamically generated list routes.
  18. # Generated using @list_route decorator
  19. # on methods of the viewset.
  20. DynamicListRoute(
  21. url=r'^{prefix}/{methodnamehyphen}{trailing_slash}$',
  22. name='{basename}-{methodnamehyphen}',
  23. initkwargs={}
  24. ),
  25. # Detail route.
  26. Route(
  27. url=r'^{prefix}/{lookup}{trailing_slash}$',
  28. mapping={
  29. 'get': 'retrieve',
  30. 'put': 'update',
  31. 'patch': 'partial_update',
  32. 'delete': 'destroy'
  33. },
  34. name='{basename}-detail',
  35. initkwargs={'suffix': 'Instance'}
  36. ),
  37. # Dynamically generated detail routes.
  38. # Generated using @detail_route decorator on methods of the viewset.
  39. DynamicDetailRoute(
  40. url=r'^{prefix}/{lookup}/{methodnamehyphen}{trailing_slash}$',
  41. name='{basename}-{methodnamehyphen}',
  42. initkwargs={}
  43. ),
  44. ]