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 model serializer for ORMS #8

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

Added model serializer for ORMS #8

nxexox opened this issue Jul 19, 2019 · 0 comments

Comments

@nxexox
Copy link
Owner

nxexox commented Jul 19, 2019

Added ModelSerializer for different ORMs.
Example:

from rest_framework import serializers


class ExampleModel(OrmModelClass):
    field_one = OrmCharFIeld(required=True, field_arg=1) . # etc


class ExampleModelSerializer(serializers.Serializer):
    class Meta:
        model = ExampleModel
        fields = ('field_one',)

# FROM OBJECT TO JSON
obj = ExampleModel(field_one='123')
ser = ExampleModelSerializer(instance=obj)
print(ser.data)
# {"field_one": "Field One"}

# FROM JSON TO OBJECT
ser = ExampleModelSerializer(data={'field_not_valid_name': None})
ser.is_valid()
print(ser.errors)
# {'field_one': 'This field is required.'}
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