Skip to main content

Django Rest Framework Extras

https://travis-ci.org/praekelt/djangorestframework-extras.svg?branch=develop https://coveralls.io/repos/github/praekelt/djangorestframework-extras/badge.svg

DRFE generates RESTful API’s for any Django models. It builds on Django Rest Framework.

Prerequisite

  1. pip install djangorestframework

  2. Add rest_framework to your INSTALLED_APPS setting in settings.py.

Installation

  1. Install or add djangorestframework-extras to your Python path.

  2. Add rest_framework_extras to your INSTALLED_APPS setting in settings.py.

Feature List

  • Generating default serializers and viewsets for all known applications to create RESTful API’s.

  • Registering all viewsets known to the application with the Django Rest Framework router.

  • Custom serializers and permissions for the default user, the staff users and superusers.

  • Custom FormMixin that Delegates validation to a normal Django form.

  • Custom Hyperlink fields and serializer, HyperlinkedRelatedField and HyperlinkedModelSerializer

Usage

User permissions and the custom UsersViewSet

djangorestframework-extras provides a custom ViewSet UsersViewSet with serializers and permissions for the default user, the staff user and the superuser.

Register UsersViewSet through the DefaultRouter:

from rest_framework_extras.users.viewsets import UsersViewSet

router = routers.DefaultRouter()

router.register(r'users', UsersViewSet, 'user')

Discovery and registration of ViewSets

Enable discovery and registration of default serializers and viewsets by adding the following to urls.py:

from rest_framework import routers
import rest_framework_extras
router = routers.DefaultRouter()

rest_framework_extras.discover(router)
rest_framework_extras.register(router)

urlpatterns = [
    url(r"^api/(?P<version>(v1))/", include(router.urls))
]

Going through the code line by line:

  1. Line 1 & 3: The router and DefaultRouter classes connects the views and urls automatically and also creates the API root.

  2. Line 5: The new discover function generates default serializers and viewsets. This function should be run before normal registration.

  3. Line 6: The new register function registers all viewsets (including the UsersViewSet), overriding any items already registered with the same name.

  4. Line 9: Define the urls by including router.urls.

Available Settings

REST_FRAMEWORK_EXTRAS

blacklist: A dictionary of the models to blacklist. By default the following models are blacklisted:

"REST_FRAMEWORK_EXTRAS": {
   "blacklist": {
        "sessions-session": {},
        "admin-logentry": {}
   },
   "authentication-classes": (SessionAuthentication, BasicAuthentication),
   "permission-classes": (DjangoModelPermissions,)
}

Tips

Change the name of the registered user model by changing the mapping parameter, such as:

rest_framework_extras.register(router, mapping=(("user", UsersViewSet),))

Restrict models that will be displayed through the Django Rest Framework by using the only and override parameters. Define a comma separated list, such as:

rest_framework_extras.discover(router, only=["auth-user", "auth-permission"])

todo: document override

Unit Testing

Run tests by using the following command:

python manage.py test rest_framework_extras.tests --settings=rest_framework_extras.tests.settings.111

License

Please see the License requirements in the LICENSE file of this repository.

Metadata

Release files for djangorestframework-extras 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangorestframework-extras 0.3.0
File Size Uploaded Provenance Actions
djangorestframework-extras-0.3.0.tar.gz 12.0 kB Without provenance Details for djangorestframework-extras-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djangorestframework-extras 0.3.0
File Interpreter ABI Platform Actions
djangorestframework_extras-0.3.0-py2.7.egg Legacy Egg format - - Details for djangorestframework_extras-0.3.0-py2.7.egg

Total release size: 51.6 kB

Release files / djangorestframework-extras-0.3.0.tar.gz

Download URL djangorestframework-extras-0.3.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
35f9a712707908d339a5e0b7ad1d77332a3d3de194f25faf7e473b99ea92ad71
BLAKE2b-256 checksum
How to use checksums
3b2d682d0243538511d2a5bcb78df4a062d03ba36463fd5c44dd4b5d4757a842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / djangorestframework_extras-0.3.0-py2.7.egg

Download URL djangorestframework_extras-0.3.0-py2.7.egg
Size 39.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
9264d3370ae400d2436a8383bbc20011c4b86466bc165772ffce09d93f8349cf
BLAKE2b-256 checksum
How to use checksums
e2df0fc825c617ee1337b1f8cc92b8d28bc3dc06b634baafec7744044438a03f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for djangorestframework-extras 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page