Git Product home page Git Product logo

drf-compound-fields's Introduction

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

See the :doc:`usage <usage>` for more information.

Project info

drf-compound-fields's People

Contributors

estebistec avatar tbarbugli avatar tigorc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.