Skip to main content

A mixin for Django REST package List Views to return an object instead of a list.

Project description

Django REST Envelop

Turn the ViewSet list endpoints to return an object rather than a list directly.

Installation

From PYPi using pip:

pip install django-rest-envelope

Usage

In your viewset views, you can use the ListEnvelopeMixin along with another mixin that defines the list() method:

class MyViewSet(ListEnvelopeMixin, ReadOnlyModelViewSet):
    envelope: "my_envelope"

In your ViewSet class that uses the mixin you have to define the envelope attribute.

Additionally, you can overwrite the get_envelope() method to tweak the behaviour of which envelope use in different situations.

Example

By default, django REST ViewSets return a list:

[
  { "id": 1, "foo": "bar" },
  { "id": 2, "foo": "baz" }
]

Once the mixin is applied to that same ViewSet, you get, instead, the following response:

{
  "my_envelope": [
    { "id": 1, "foo": "bar" },
    { "id": 2, "foo": "baz" }
  ]
}

Licence

This package is distributed under MIT Licence.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

django_rest_envelope-1.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file django_rest_envelope-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_rest_envelope-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb40d0553162c6de85b60fb494445845869a705d63cbef5f25407306dc564af2
MD5 1d41c5ede29ee562a66b6ce2e6f661ac
BLAKE2b-256 4a5a57245b9428d432076fafb580f23f43951d0013d6ccb52e40d9bc732f0c99

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