Skip to content

Added create python object class from serializer data. #7

@nxexox

Description

@nxexox

Added python class objects from serializer data.
Example:

from rest_framework import serializers

class ExampleObject(object):
    field_one = 10
    def __str__(self):
        return 'ExampleObject(field_one={})'.format(self.field_one)

class ExampleObjectSerializer(serializers.Serializer):
    class Meta:
        to_object = ExampleObject

ser = ExampleObjectSerializer(data={'field_one': 100})
ser.is_valid()
obj = ser.get_object()
print(obj)
# 'ExampleObject(field_one=100)'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions