DRF Shortcuts
Shortcuts for speeding up your development based on Django REST Framework (DRF).
Overview
DRF shortcuts library allows you to:
- Expose your Django model class using a one-liner
register_standard_endpoint(your_router, YourModel). Exposed API endpoint will support search & ordering of items for suitable fields (backed up bySearchFilter&OrderingFilterfilter backends) and will be nicely documented in both Browseable API & upon issuingOPTIONSrequests against it. - Create
rest_framework.viewsets.ModelViewSetbased viewset class for your Django model using a one-linercreate_standard_viewset_class(YourModel). Viewset capabilities will be similar to the one registered usingregister_standard_endpointshortcut. - Create JS-based clients friendly serializer class for your Django model using a one-liner
create_standard_serializer_class(YourModel). - Use library classes & helper functions to tailor your own DRF shortcuts.
Requirements
- Python 3.6+
- Django 2.0+
- Django REST Framework 3.8+
Installation
Install using pip:
pip install drf-shortcuts
Examples
Exposing a Django model:
# in urls.py
from rest_framework.routers import DefaultRouter
from drf_shortcuts.urls import register_standard_endpoint
from my_fancy_app.models import MyModel
router = DefaultRouter()
register_standard_endpoint(router, MyModel)
# ... more URL configuration code here ...
urlpatterns = router.urls
Creating a viewset class:
# in views.py
from drf_shortcuts.views import create_standard_viewset_class
from my_fancy_app.models import MyModel
MyModelViewSet = create_standard_viewset_class(MyModel)
Creating a serializer class:
# in serializers.py
from drf_shortcuts.serializers import create_standard_serializer_class
from my_fancy_app.models import MyModel
MyModelSerializer = create_standard_serializer_class(MyModel)
Customizing a view using helpers:
# in views.py
from rest_framework.viewsets import ReadOnlyModelViewSet
from drf_shortcuts.views import append_search_info_to_docstring
from drf_shortcuts.serializers import create_standard_serializer_class
from my_fancy_app.models import MyModel
@append_search_info_to_docstring
class MyModelViewSet(ReadOnlyModelViewSet):
serializer_class = create_standard_serializer_class(MyModel)
# ... rest of the view code ...
Documentation
Visit project's GitHub Pages.
Metadata
Release files for drf_shortcuts 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf_shortcuts-0.0.2.tar.gz | 7.5 kB | Details |
Release files / drf_shortcuts-0.0.2.tar.gz
| Download URL | drf_shortcuts-0.0.2.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0024bc85bb5baf91b86b9b38ebaed784b8755d721a10dae2aa1332f50c312b35
|
|
BLAKE2b-256 checksum How to use checksums |
ad70d89c637b55988a88a5392a22ab4347caf33b830777a68980cd54d6f13395
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|