Skip to main content

Serialize a partial subset of fields in the API

Project description

Installation

pip install djangorestframework-queryfields

Quickstart

Specify your base model serializer like this:

from rest_framework.serializers import ModelSerializer
from drf_queryfields import QueryFieldsMixin

class MyModelSerializer(QueryFieldsMixin, ModelSerializer):
    pass

Usage

GET http://127.0.0.1:8000/snippets/

HTTP/1.1 200 OK
...
[
  {
    "id": 1,
    "title": "",
    "code": "foo = \"bar\"\n",
    "linenos": false,
    "language": "python",
    "style": "friendly"
  },
  {
    "id": 2,
    "title": "",
    "code": "print \"hello, world\"\n",
    "linenos": false,
    "language": "python",
    "style": "friendly"
  }
]


GET http://127.0.0.1:8000/snippets/?fields=id,code

HTTP/1.1 200 OK
...
[
  {
    "id": 1,
    "code": "foo = \"bar\"\n",
  },
  {
    "id": 2,
    "code": "print \"hello, world\"\n",
  }
]


GET http://127.0.0.1:8000/snippets/?fields!=code

HTTP/1.1 200 OK
...
[
  {
    "id": 1,
    "title": "",
    "linenos": false,
    "language": "python",
    "style": "friendly"
  },
  {
    "id": 2,
    "title": "",
    "linenos": false,
    "language": "python",
    "style": "friendly"
  }
]

Feedback

For feature requests or bug reports, please create an issue here.

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-queryfields-1.0.0.tar.gz (3.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