skip to navigation
skip to content

djangorestframework-constant-field 0.9.1

A simple Constant Field definition for Django REST Framework

A ConstantField type for Django REST Framework.


pip install djangorestframework-constant-field


Using this is really simple, just set the value attribute on your serializer:

from rest_framework import serializers
from rest_framework_constant.fields import ConstantField

class MySerializer(serializers.Serializer):
    """Custom Serializer

    my_value = ConstantField(value='My Value')

serialized = MySerializer()


# {
#     'my_value': 'My Value',
# }


This is useful when you’re building a serializer to integrate into some third party system where some of your fields are pre-defined. The above example is equivalent to:

from rest_framework import serializers

class MySerializer(serializers.Serializer):
    """Custom Serializer

    my_value = serializers.SerializerMethodField()

    def get_my_value(self, obj):
        """Excessive code.
        return 'My Value'

Testing & Contributing

To build and test this package, simply fork this repo and:

git clone<yourname>/djangorestframework-constant-field.git

cd djangorestframework-constant-field
pip install -r requirements.txt
python test

The current app is almost completely contained inside rest_framework_constant.

File Type Py Version Uploaded on Size
djangorestframework-constant-field-0.9.1.tar.gz (md5) Source 2017-06-16 2KB
djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl (md5) Python Wheel 3.5 2017-06-16 5KB