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.

Files for drf-payload-customizer, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size drf_payload_customizer-0.0.1-py3.6.egg (10.9 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size drf-payload-customizer-0.0.1.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page