Skip to main content
https://badge.fury.io/py/drf-compound-fields.png https://travis-ci.org/estebistec/drf-compound-fields.png?branch=master https://pypip.in/d/drf-compound-fields/badge.png Test coverage

Overview

Django-REST-framework serializer fields for compound types. Django-REST-framework provides the ability to deal with multiple objects using the many=True option on serializers. That allows for lists of objects and for fields to be lists of objects.

This package expands on that and provides fields allowing:

  • Lists of simple (non-object) types, described by other serializer fields.

  • Fields that allow values to be a list or individual item of some type.

  • Dictionaries of simple and object types.

  • Partial dictionaries which include keys specified in a list.

A quick example:

from drf_compound_fields.fields import DictField
from drf_compound_fields.fields import ListField
from drf_compound_fields.fields import ListOrItemField
from drf_compound_fields.fields import ListField
from rest_framework import serializers

class EmailContact(serializers.Serializer):
    email = serializers.EmailField()
    verified = serializers.BooleanField()

class UserProfile(serializers.Serializer):
    username = serializers.CharField()
    email_contacts = EmailContact(many=True)  # List of objects: possible with REST-framework alone
    # This is the new stuff:
    skills = ListField(serializers.CharField())  # E.g., ["javascript", "python", "ruby"]
    name = ListOrItemField(serializers.CharField())  # E.g., "Prince" or ["John", "Smith"]
    bookmarks = DictField(serializers.URLField())  # E.g., {"./": "http://slashdot.org"}
    measurements = PartialDictField(included_keys=['height', 'weight'], serializers.IntegerField())

Project info

History

2.0.0 (2019-09-21)

  • Deprecate Python 2 support

  • Fix #29

1.0.0 (2016-02-29)

  • Upgrade ListOrItemField and PartialDictField for django-rest-framework 3.0 and beyond

  • Remove ListField and DictField, as they now come with django-rest-framework

0.2.2 (2014-08-10)

Correct validation behaviors when fields are used in embedded serializers. Also correction to the list and dict type checks for None values (#15, #16, #18).

  • Implement initialize and field_from_native to ensure proper validation in embedded serializers.

  • Give the fields distinct validate and run_validators implementations that don’t call each other.

  • Don’t apply the list and dict type checks for None values.

0.2.1 (2014-04-23)

Loosen dependency versions

  • Remove explicit dependency on Django

  • Loosen rest-framework to any version before 3

0.2.0 (2014-03-16)

  • Documentation (#3)

  • Collect messages of nested errors, instead of error objects (#12)

  • Add ListOrItemField type (#5, #11)

  • Fix PartialDictField validation and handling of badly-typed values

  • Switch project tests to py.test (#10)

0.1.0 (2014-03-06)

First PyPI release of rest-framework serializer compound-fields (#1). Provides:

  • ListField (#4, #7)

  • DictField

  • PartialDictField (#8, #9)

Metadata

Release files for drf-compound-fields 2.0.0

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

Source distribution (sdist)

Source distribution for drf-compound-fields 2.0.0
File Size Uploaded
drf-compound-fields-2.0.0.tar.gz 6.7 kB Details

Release files / drf-compound-fields-2.0.0.tar.gz

Download URL drf-compound-fields-2.0.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
12e8acf5b9971f4e3be0542174fd0728bc47e718bdd82f0f85daa9b83c1cc8c5
BLAKE2b-256 checksum
How to use checksums
5e939296321434bb74b0c99ecd6c64b1e3171efeb8c19cdb11aa2543cf099195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

2.0.0 This release

1 release file

1.0.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

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