Skip to main content

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.

Metadata

Release files for djangorestframework-constant-field 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangorestframework-constant-field 0.9.1
File Size Uploaded Provenance
djangorestframework-constant-field-0.9.1.tar.gz 2.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for djangorestframework-constant-field 0.9.1
File Interpreter ABI Platform
djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 7.9 kB

Release files / djangorestframework-constant-field-0.9.1.tar.gz

Download URL djangorestframework-constant-field-0.9.1.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e24a994bd28ca563f51a9c4fdc4672eda3facb1574a22162f721bb2e2fa15c49
BLAKE2b-256 checksum
How to use checksums
09cde4b157d4e6dc6283766d9e715556fc7ef7f62b7abb0338a9675b004ecf03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl

Download URL djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl
Size 5.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b65d0cafffeab43bf5c97b1dbb6bc57dd0da9cf39693407627cb2f73f7141072
BLAKE2b-256 checksum
How to use checksums
7bb7328917d6227de3268ee3651f41d9399a7fde017c335dea9a33434dfec1a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for djangorestframework-constant-field 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files No provenance

0.9.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page