This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Use django-candv-choices with django-rest-framework.

Table of contents

Installation

Install from PyPI:

$ pip install django-rf-candv-choices

Usage

Serializing choices

For example, you have some model which uses candv_x.django.choices.ChoiceField to store one of allowed values. This might be a User model, which has user_role field, where values for user_role are defined by USER_ROLES constants container.

Use candv_x.rest_framework.choices.ChoiceField for user_role serialization:

from rest_framework import serializers
from candv_x.rest_framework.choices import ChoiceField

from .constants import USER_ROLES
from .models import User


class UserSerializer(serializers.ModelSerializer):
    user_role = ChoiceField(USER_ROLES)

    class Meta:
        model = User
        fields = ('id', 'name', 'user_role', )

Exposing choices to the outer world

If you need to expose list of possible choices for your field, then you can use a ChoicesList base view to get a class-based view:

from candv_x.rest_framework.choices import ChoicesList

from .constants import USER_ROLES


class UserRoleList(ChoicesList):
    choices = USER_ROLES

The only thing you need to do is to define choices attribute.

There is a faster way also: you can use a coalitions_list view factory to get a function-based view:

from candv_x.rest_framework.choices import simple_choices_list

from .constants import USER_ROLES


user_role_list = simple_choices_list(USER_ROLES)

Changelog

You can click a version name to see a diff with the previous one.

  • 1.0.0 (Aug 1, 2015)

    Initial version

Release History

Release History

1.0.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-rf-candv-choices-1.0.0.tar.gz (6.1 kB) Copy SHA256 Checksum SHA256 Source Aug 1, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting