Common shortcuts for speeding up your development based on Django REST Framework (DRF).
Project description
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
&OrderingFilter
filter backends) and will be nicely documented in both Browseable API & upon issuingOPTIONS
requests against it. - Create
rest_framework.viewsets.ModelViewSet
based 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_endpoint
shortcut. - 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
drf_shortcuts-0.0.2.tar.gz
(7.5 kB
view details)
File details
Details for the file drf_shortcuts-0.0.2.tar.gz
.
File metadata
- Download URL: drf_shortcuts-0.0.2.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0024bc85bb5baf91b86b9b38ebaed784b8755d721a10dae2aa1332f50c312b35 |
|
MD5 | a8988cbcb31654dffdb1c84bb7bb5be2 |
|
BLAKE2b-256 | ad70d89c637b55988a88a5392a22ab4347caf33b830777a68980cd54d6f13395 |