Skip to main content

This package allows you to customize your django-rest-framework serializer i/o to make modern frontend frameworks happy.

Project description

drf-payload-customizer

License Contributing 3yourminD-Careers Stars

This package allows you to customize your django-rest-framework serializer i/o to make modern frontend frameworks happy.

Requirements

The mixin requires you to have the following dependencies:

djangorestframework==3.8.2
inflection==0.3.1

However, you will require Django==2.1.2 to run the unit tests.

Use it in your project

from drf_payload_customizer.mixins import PayloadCustomizationMixin

class CustomTestModelSerializer(PayloadCustomizationMixin, ModelSerializer):
    class Meta:
        model = TestModel
        fields = ('parama', 'param_b',)
        field_mappings = {
            'parama': 'paramA'
        }
        
# Now your serializer would output: 
test_serializer = CustomTestModelSerializer(obj)
JSONRenderer().render(test_serializer.data)
> {'paramA': '', 'paramB': None}

# Your serializer also admits input in the same format: 
content = json.dumps({'paramA': 'testA', 'paramB': 3}).encode()
stream = BytesIO(content)
data = JSONParser().parse(stream)
serializer = CustomTestModelSerializer(data=data)
self.assertTrue(serializer.is_valid())
> True

To run tests

cd drf_payload_customizer
# Make sure you change to a virutal environment according to your project setup
python setup.py install 
pip install -r requirements.txt 
cd tests/test_app/ 
python manage.py test 

Project details


Download files

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

Source Distribution

drf-payload-customizer-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

drf_payload_customizer-0.0.1-py3.6.egg (10.9 kB view details)

Uploaded Source

File details

Details for the file drf-payload-customizer-0.0.1.tar.gz.

File metadata

  • Download URL: drf-payload-customizer-0.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for drf-payload-customizer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0543b5eb5957bf9703f005b400811c78768e03ce62dfa33ac749ea51454d545b
MD5 09a6ac449c30f56970d6053bdbe83ba2
BLAKE2b-256 7b6777db37e079651542f69d9bc8621a342bb959701bc9d8e8c9ea4c9cedc6ba

See more details on using hashes here.

File details

Details for the file drf_payload_customizer-0.0.1-py3.6.egg.

File metadata

  • Download URL: drf_payload_customizer-0.0.1-py3.6.egg
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for drf_payload_customizer-0.0.1-py3.6.egg
Algorithm Hash digest
SHA256 9c7b10d83bd1639ae8064c9a049a4b7ef8b2c91b096a25e11bc27118661af605
MD5 23f36ae41d84e4471897bb9dfc389a7d
BLAKE2b-256 97ccbd18a4eb05659c55c02f70f33830871a2def9a9765100886218113ec0e93

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page