Skip to content

Instantly share code, notes, and snippets.

@Soyuzbek
Created February 1, 2022 16:21
Show Gist options
  • Save Soyuzbek/afbcfce1b9d116c48bc549486ee53eed to your computer and use it in GitHub Desktop.
Save Soyuzbek/afbcfce1b9d116c48bc549486ee53eed to your computer and use it in GitHub Desktop.
from rest_framework.routers import SimpleRouter, Route, DynamicRoute
class LookupFreeRouter(SimpleRouter):
routes = [
# CRUD route.
Route(
url=r'^{prefix}{trailing_slash}$',
mapping={
'get': 'retrieve',
'post': 'create',
'put': 'update',
'patch': 'partial_update',
'delete': 'destroy'
},
name='{basename}-list, create, update, partial update',
detail=False,
initkwargs={'suffix': 'CRUD'}
),
# Dynamically generated action routes. Generated using
# @action(detail=False) decorator on methods of the viewset.
DynamicRoute(
url=r'^{prefix}/{url_path}{trailing_slash}$',
name='{basename}-{url_name}',
detail=False,
initkwargs={}
),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment