Skip to main content

Restrict fields returned by DRF serializers

Project description

https://img.shields.io/pypi/v/drf_restricted_fields.svg https://github.com/tj-django/drf-restricted-fields/actions/workflows/test.yml/badge.svg Documentation Status Updates

Features

Restrict fields returned by DRF serializers using the only query parameter

GET http://127.0.0.1:8000/api/users/?only=id&only=name

Serialize only the id and name fields.

{
    "count": 198,
    "next": "http://127.0.0.1:8000/api/users/?only=id&only=name&page=1",
    "previous": null,
    "results":[
        {
            "id": 1,
            "name": "Test"
        },
        ...
    ],
}

Defer fields returned by DRF serializers using the defer query parameter

GET http://127.0.0.1:8000/api/users/?defer=name&defer=age

Serialize only the id and name fields.

{
    "count": 198,
    "next": "http://127.0.0.1:8000/api/users/?defer=name&defer=age&page=1",
    "previous": null,
    "results":[
        {
            "id": 1,
        },
        ...
    ],
}

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

drf_restricted_fields-0.0.1.tar.gz (6.9 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page