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
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 Distributions
Built Distribution
File details
Details for the file django_rest_envelope-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: django_rest_envelope-1.1.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb40d0553162c6de85b60fb494445845869a705d63cbef5f25407306dc564af2 |
|
MD5 | 1d41c5ede29ee562a66b6ce2e6f661ac |
|
BLAKE2b-256 | 4a5a57245b9428d432076fafb580f23f43951d0013d6ccb52e40d9bc732f0c99 |