2π
β
I donβt think there is a direct way to get all the actions specified in a ViewSet class. But, the Routers are usually generating the URLs in a similar way. So, Iβm going to use the DRF Routers here,
from rest_framework.routers import SimpleRouter
router = SimpleRouter()
routes = router.get_routes(YourViewsetClass)
action_list = []
for route in routes:
action_list += list(route.mapping.values())
distinct_action_list = set(action_list)
π€JPG
1π
Iβm using rest_framework version 3.11.2
and there you can do it like that:
actions = [action for action in YourViewsetClass.get_extra_actions()]
action_names = [action.__name__ for action in YourViewsetClass.get_extra_actions()]
action_url_names = [action.url_name for action in YourViewsetClass.get_extra_actions()]
π€binaryEcon
- [Django]-Mail address validation in python/django
- [Django]-Pyvmomi Get RAM/CPU Usage VSphere SDK 5.5?
- [Django]-Adding a **kwarg to a class
- [Django]-TypeError: argument of type 'function' is not iterable when starting django runserver
- [Django]-Optimizing setup and teardown for sample django model using django_nose and django-dynamic-fixture
Source:stackexchange.com