Skip to content

Commit 85ba4d2

Browse files
author
Maxence
committed
Manage allowed_methods on ModelViewSets
1 parent 5a43d41 commit 85ba4d2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: rest_framework_docs/api_endpoint.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
from rest_framework_docs import SERIALIZER_FIELDS
77

88

9+
VIEWSET_METHODS = {
10+
'List': ['get', 'post'],
11+
'Instance': ['get', 'put', 'patch', 'delete'],
12+
}
13+
14+
915
class ApiEndpoint(object):
1016

1117
def __init__(self, pattern, parent_pattern=None):
@@ -37,7 +43,9 @@ def __get_path__(self, parent_pattern):
3743
return simplify_regex(self.pattern.regex.pattern)
3844

3945
def __get_allowed_methods__(self):
40-
return [m.upper() for m in self.callback.cls.http_method_names if hasattr(self.callback.cls, m)]
46+
callback_cls = self.callback.cls
47+
return [m.upper() for m in callback_cls.http_method_names if hasattr(callback_cls, m) or
48+
(issubclass(callback_cls, ModelViewSet) and m in VIEWSET_METHODS.get(self.callback.suffix))]
4149

4250
def __get_docstring__(self):
4351
return inspect.getdoc(self.callback)

0 commit comments

Comments
 (0)