Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema generator with automatic bulk action support #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,19 @@ please refer to Django REST
`docs <http://www.django-rest-framework.org/api-guide/filtering>`_.
Either way, please use bulk deletes with extreme caution since they
can be dangerous.

Schemas and interactive documentation
-------------------------------------

You can use BulkSchemaGenerator for your interactive docs needs::

from rest_framework.documentation import include_docs_urls
from rest_framework_bulk.schemas import SchemaGenerator

urlpatterns = [
...
url(r'^docs/', include_docs_urls(title='My API title', generator_class=SchemaGenerator))
]

This will include bulk actions in docs for appropriate viewsets.
Refer to DRF docs for other details on interactive documentation and schemas.
14 changes: 14 additions & 0 deletions rest_framework_bulk/drf3/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import rest_framework


class BulkSchemaGenerator(rest_framework.schemas.SchemaGenerator):
"""
Customized schema generator with bulk actions included
"""

default_list_mapping = {
'get': 'list',
'put': 'bulk_update',
'patch': 'bulk_partial_update',
'delete': 'bulk_destroy',
}
7 changes: 7 additions & 0 deletions rest_framework_bulk/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import print_function, unicode_literals
import rest_framework


# import schema generator only for DRF 3+
if not str(rest_framework.__version__).startswith('2'):
from .drf3.schemas import * # noqa