Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added create python object class from serializer data. #7

Open
nxexox opened this issue Jul 19, 2019 · 0 comments
Open

Added create python object class from serializer data. #7

nxexox opened this issue Jul 19, 2019 · 0 comments

Comments

@nxexox
Copy link
Owner

nxexox commented Jul 19, 2019

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)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant