Metadata-Version: 2.0
Name: djangorestframework-constant-field
Version: 0.9.1
Summary: A simple Constant Field definition for Django REST Framework
Home-page: https://github.com/mypebble/djangorestframework-constant-field.git
Author: Scott Walton
Author-email: scott.walton@mypebble.co.uk
License: Public Domain
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.9
Classifier: Framework :: Django :: 1.10
Classifier: Framework :: Django :: 1.11
Requires-Dist: django
Requires-Dist: djangorestframework

Constant Field Type for DRF
===========================

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:

.. code:: python

    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:

.. code:: python

    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:

.. code:: bash

    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``.


