Django-REST-framework serializer fields for compound types.
Project description
.. image:: https://badge.fury.io/py/drf-compound-fields.png
:target: http://badge.fury.io/py/drf-compound-fields
.. image:: https://travis-ci.org/estebistec/drf-compound-fields.png?branch=master
:target: https://travis-ci.org/estebistec/drf-compound-fields
.. image:: https://pypip.in/d/drf-compound-fields/badge.png
:target: https://crate.io/packages/drf-compound-fields?version=latest
.. image:: https://coveralls.io/repos/estebistec/drf-compound-fields/badge.png?branch=master
:target: https://coveralls.io/r/estebistec/drf-compound-fields?branch=master
:alt: Test coverage
Overview
========
`Django-REST-framework <http://www.django-rest-framework.org/>`_
`serializer fields <http://www.django-rest-framework.org/api-guide/fields>`_ for compound types.
Django-REST-framework provides the ability to
`deal with multiple objects <http://www.django-rest-framework.org/api-guide/serializers#dealing-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())
See the :doc:`usage <usage>` for more information.
Project info
============
* Free software: BSD license
* `Documentation <http://drf-compound-fields.rtfd.org>`_
* `Source code <https://github.com/estebistec/drf-compound-fields>`_
* `Issue tracker <https://github.com/estebistec/drf-compound-fields/issues>`_
* `CI server <https://travis-ci.org/estebistec/drf-compound-fields>`_
* IRC: no channel but see AUTHORS for individual nicks on freenode.
* Mailing list: None yet, but please log an `issue <https://github.com/estebistec/drf-compound-fields/issues>`_ if you want to have discussions about this package.
History
-------
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)
:target: http://badge.fury.io/py/drf-compound-fields
.. image:: https://travis-ci.org/estebistec/drf-compound-fields.png?branch=master
:target: https://travis-ci.org/estebistec/drf-compound-fields
.. image:: https://pypip.in/d/drf-compound-fields/badge.png
:target: https://crate.io/packages/drf-compound-fields?version=latest
.. image:: https://coveralls.io/repos/estebistec/drf-compound-fields/badge.png?branch=master
:target: https://coveralls.io/r/estebistec/drf-compound-fields?branch=master
:alt: Test coverage
Overview
========
`Django-REST-framework <http://www.django-rest-framework.org/>`_
`serializer fields <http://www.django-rest-framework.org/api-guide/fields>`_ for compound types.
Django-REST-framework provides the ability to
`deal with multiple objects <http://www.django-rest-framework.org/api-guide/serializers#dealing-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())
See the :doc:`usage <usage>` for more information.
Project info
============
* Free software: BSD license
* `Documentation <http://drf-compound-fields.rtfd.org>`_
* `Source code <https://github.com/estebistec/drf-compound-fields>`_
* `Issue tracker <https://github.com/estebistec/drf-compound-fields/issues>`_
* `CI server <https://travis-ci.org/estebistec/drf-compound-fields>`_
* IRC: no channel but see AUTHORS for individual nicks on freenode.
* Mailing list: None yet, but please log an `issue <https://github.com/estebistec/drf-compound-fields/issues>`_ if you want to have discussions about this package.
History
-------
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)
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
Close
Hashes for drf-compound-fields-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 500af332d47911fb5d1e349e15963cd57e56c96d61eafa5d95607a008734abdc |
|
MD5 | 999168ac0303c4ea781da9cf47f841c1 |
|
BLAKE2b-256 | fe8a13d6062c1eb4bea00d87135be80d826c09b1e808a9d49b89934a243fc469 |