Have is_list_view
recognise RetrieveModel… views by carltongibson · Pull Request #5480 · encode/django-rest-framework (original) (raw)
@matteius Hi. Yes, I looked again at your test case today. I noticed the as_view()
— which isn't right, so why it didn't work.
as_view()
returns a callback that takes a request, instantiates a view instance, calls dispatch on it and returns the response.
Calling isinstance
on this callback (obviously, once you've seen it) doesn't give the result we're after. We need the view
inside the wrapper.
SchemaGenerator
has a whole method for mapping callbacks back to views:
def create_view(self, callback, method, request=None): |
---|
""" |
Given a callback, return an actual view instance. |
""" |
view = callback.cls() |
for attr, val in getattr(callback, 'initkwargs', {}).items(): |
setattr(view, attr, val) |
view.args = () |
view.kwargs = {} |
view.format_kwarg = None |
view.request = None |
view.action_map = getattr(callback, 'actions', None) |
actions = getattr(callback, 'actions', None) |
if actions is not None: |
if method == 'OPTIONS': |
view.action = 'metadata' |
else: |
view.action = actions.get(method.lower()) |
if request is not None: |
view.request = clone_request(request, method) |
return view |
It's this that we inspect to generate the schema.