Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

A simple Constant Field definition for Django REST Framework

Project description

A ConstantField type for Django REST Framework.

Installation

pip install djangorestframework-constant-field

Usage

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

print(serialized.data)

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

Why?

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 git@github.com:<yourname>/djangorestframework-constant-field.git

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

The current app is almost completely contained inside rest_framework_constant.

Project details


Release history Release notifications

This version
History Node

0.9.1

History Node

0.9.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl (5.2 kB) Copy SHA256 hash SHA256 Wheel 3.5 Jun 16, 2017
djangorestframework-constant-field-0.9.1.tar.gz (2.7 kB) Copy SHA256 hash SHA256 Source None Jun 16, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page