Skip to main content

This package provides utils for Django Rest Framework API views and serializers for limiting fields returned in responses thus limiting size and complexity of database requests.

Project description

DRF fields limiting

example workflow Coverage Status

About

This package provides utils for Django Rest Framework API views and serializers for limiting fields returned in responses thus limiting size and complexity of database requests.

Install

pip install drf-fields-limiting

Usage

Inherit from LimitedFieldsView or LimitedFieldsViewSet and configure it to enable fields limiting. View limits fields of serialized object in response with respect to Fields HTTP header.

If header is not present or is empty show all fields. Fields limiting works only in GET requests.

LIMITED_FIELDS_CONFIG holds map of field name - operation to perform on queryset (from fields_limiting.operations). It should contains entries for all fields declared in serializer_class.

...
class MySerializer(LimitedFieldsSerializer, serializers.ModelSerializer):
    
    class Meta:
        model = MyModel
        fields = (
            'char_field',
            'int_field',
            'foreign',
        )
    ...

class MyViewSet(LimitedFieldsViewSet, viewsets.ModelViewSet):
    ...
    LIMITED_FIELDS_CONFIG = {
        'char_field': Only('char_field'),
        'int_field': Only('int_field'),
        'foreign': SelectRelated('foreign'),
    }
    serializer_class = MySerializer
    ...

All available operations are in drf_fields_limiting.operations module.

Example GET query:

GET /api/v1/base/my/ HTTP/1.1
Authorization: Token h3r315myt0k3n
Accept: application/json
Content-Type: application/json
Fields: char_field,int_field

License

The DRF complete autocomplete package is licensed under the FreeBSD License.

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-fields-limiting-1.0.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

drf_fields_limiting-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file drf-fields-limiting-1.0.0.tar.gz.

File metadata

  • Download URL: drf-fields-limiting-1.0.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for drf-fields-limiting-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c0ff32bc5169130ef5a9c52cdea2fef65395f1a5e4184aac1d7a8b10f85b754d
MD5 674a855d8c5d1f75133222a3c2a766e1
BLAKE2b-256 e2721b3db50ae7f8fa997a350ab19fc8d6a5cf3f6652d2be8e94eb6fab243c29

See more details on using hashes here.

File details

Details for the file drf_fields_limiting-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: drf_fields_limiting-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for drf_fields_limiting-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4720f298b5ce980bb0343210e3e3637f5c2bfc045871c23384f5ccdace55c6d
MD5 99501af24fff384344a7c2645e279a1f
BLAKE2b-256 f18e05e7c0a5138c244fb564564cba72caa7eb91e61a799d62538e5489598538

See more details on using hashes here.

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