Skip to main content

No project description provided

Project description

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.

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": {}
   }
}

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 overwrite parameters. Define a comma separated list, such as:

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

Unit Testing

Run tests by using the following command:

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

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangorestframework-extras-0.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

djangorestframework_extras-0.1-py2.7.egg (33.9 kB view details)

Uploaded Source

File details

Details for the file djangorestframework-extras-0.1.tar.gz.

File metadata

File hashes

Hashes for djangorestframework-extras-0.1.tar.gz
Algorithm Hash digest
SHA256 e5aaeb7e65e6016897042d8ee7f07a1d39886c58d9e7f0bfeafedcac8496d97a
MD5 038a5343a6926efc9ae72dc5514ad925
BLAKE2b-256 7fffd9e2b6326fbe2a5e7ef5eddec1b42737a7dc0c0240ad18fc75c1187d6dc4

See more details on using hashes here.

File details

Details for the file djangorestframework_extras-0.1-py2.7.egg.

File metadata

File hashes

Hashes for djangorestframework_extras-0.1-py2.7.egg
Algorithm Hash digest
SHA256 72e2ac78d211b2e21c9238bfca36881d181e4d7d9b6d5616d601bde86daa71c6
MD5 d29eb6f75110c3af3f8aa751791600c4
BLAKE2b-256 e94825ff68e602d7f7b3d45bd61270b375f32dfb56ab7904f41b877f9b9c4a72

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page