Skip to main content

Keyed Lists for Django REST Framework

This package supports the serialization and deserialization of a list of objects stored in a dict where a unique value from the object (often a pk) is used as the key in the dict. For example,

{
    "1": {<other fields for object with id 1>},
    "2": {<other fields for object with id 2>},
    ...
}

Install

pip install drf-keyed-list

Usage

The following is a usage example:

class MySerializer(ModelSerializer):

    class Meta:
        list_serializer_class = KeyedListSerializer
        keyed_list_serializer_field = 'id'

By replacing the list_serializer_class, this behavior will only be enabled when the many=True flag is used:

instance = {
   "id": "pk_val",
   "field1": "val1",
   "field2": "val2",
   ...
}

serializer = MySerializer(data=instance)
# this should work
serializer.is_valid()
serializer.save()

keyed_list = {
   "pk_val": {
       "field1": "val1",
       "field2": "val2",
       ...
   }
}

# many=True will trigger the keyed-list behavior
serializer = MySerializer(data=keyed_list, many=True)
# this should also work
serializer.is_valid()
serializer.save()

NOTE: keyed_list_serializer_field MUST refer to a Unique field or key collision may occur during serialization, plus undefined deserializaiton behavior if used in combination with nested writable serializers (e.g. drf-writable-nested). At this time, the package does not make any effort to verify that a Unique field has been selected.

Authors

2018, Clayton Daley III

Metadata

Release files for drf-keyed-list 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for drf-keyed-list 0.0.2
File Interpreter ABI Platform Actions
drf_keyed_list-0.0.2-py3-none-any.whl Python 3 none any Details for drf_keyed_list-0.0.2-py3-none-any.whl

Release files / drf_keyed_list-0.0.2-py3-none-any.whl

Download URL drf_keyed_list-0.0.2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac14f11db56b83eba15524c560fe217aadcb2363c39343673ef17bcb0000fc7b
BLAKE2b-256 checksum
How to use checksums
36f24dbac73a8d6f718317035cb0aaefff53a561596d5b94b57fceca4d11c17a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

Security for drf-keyed-list 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page