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

djangorestframework_queryfields-1.0.0-py2.py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 2 Python 3

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