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 | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file djangorestframework-constant-field-0.9.1.tar.gz
.
File metadata
- Download URL: djangorestframework-constant-field-0.9.1.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e24a994bd28ca563f51a9c4fdc4672eda3facb1574a22162f721bb2e2fa15c49 |
|
MD5 | f9d42c4485541c050fb7a1e7d18762a9 |
|
BLAKE2b-256 | 09cde4b157d4e6dc6283766d9e715556fc7ef7f62b7abb0338a9675b004ecf03 |
File details
Details for the file djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl
.
File metadata
- Download URL: djangorestframework_constant_field-0.9.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b65d0cafffeab43bf5c97b1dbb6bc57dd0da9cf39693407627cb2f73f7141072 |
|
MD5 | 678054ec053dba130d22f0699b90a0af |
|
BLAKE2b-256 | 7bb7328917d6227de3268ee3651f41d9399a7fde017c335dea9a33434dfec1a4 |