ChoiceField that shows display value

10 views
Skip to first unread message

Rory Geoghegan

unread,
Nov 8, 2015, 12:21:19 PM11/8/15
to Django REST framework
What I (think I) want is, given like a ChoiceField like so:

    class FoodSerializer(serializers.Serializer):
        food_choices = (('pasta','Delicious Pasta'), ('pizza', 'Big pizza'))
        food = ChoiceField(choices=food_choices)

That would serialize to:

    {
        'food': {
            'value': 'pasta',
            'display_value': 'Delicious Pasta',
        }
    }

, and, respectively, should be able to deserialize the following to match the above:

    {
        'food': 'pasta',
    }

or
    
    {
        'food': {
            'value': 'pasta',
            'display_value': 'Delicious Pasta',
        }
    }

Does anyone know of a python package that will do that? Otherwise, I may write it myself.
Reply all
Reply to author
Forward
0 new messages