Metadata-Version: 2.1
Name: django-rest-envelope
Version: 1.1.0
Summary: A mixin for Django REST package List Views to return an object instead of a list.
Author-email: Ferran Jovell <ferran.jovell+gh@gmail.com>
Project-URL: homepage, https://github.com/mrswats/django-rest-envelope
Project-URL: Bug Tracker, https://github.com/mrswats/django-rest-envelope/issues
Keywords: django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENCE
Requires-Dist: Django >=4.1.1
Requires-Dist: djangorestframework >=3.11.0
Provides-Extra: test
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: pytest-django ; extra == 'test'

# 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:

```python
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:

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

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

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

## Licence

This package is distributed under [MIT Licence](./LICENCE).
