Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Django-REST-framework serializer fields for compound types.

License

Notifications You must be signed in to change notification settings

depop-archive/drf-compound-fields

 
 

Repository files navigation

image

image

image

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())

See the usage <usage> for more information.

Project info

About

Django-REST-framework serializer fields for compound types.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 94.3%
  • Makefile 5.7%