Add swagger_fake_view marker to help detect fake views in get_serializer

Cleaner fix for #154
This commit is contained in:
Cristi Vîjdea
2018-06-29 17:46:05 +03:00
parent e0aec3ff45
commit 696ec3a94a
3 changed files with 17 additions and 1 deletions
+9
View File
@@ -174,6 +174,15 @@ in a few ways:
:ref:`@swagger_auto_schema <custom-spec-swagger-auto-schema>`, to prevent ``get_serializer`` from being called on
the view
* :ref:`exclude your endpoint from introspection <custom-spec-excluding-endpoints>`
* use the ``swagger_fake_view`` marker to detect requests generated by ``drf-yasg``:
.. code-block:: python
def get_serializer_class(self):
if getattr(self, 'swagger_fake_view', False):
return TodoTreeSerializer
raise NotImplementedError("must not call this")
.. _SCRIPT_NAME: https://www.python.org/dev/peps/pep-0333/#environ-variables
.. _FORCE_SCRIPT_NAME: https://docs.djangoproject.com/en/2.0/ref/settings/#force-script-name