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

Support for model serializer with django-rest-framework #185

Open
kiraware opened this issue Jan 5, 2023 · 4 comments
Open

Support for model serializer with django-rest-framework #185

kiraware opened this issue Jan 5, 2023 · 4 comments

Comments

@kiraware
Copy link

kiraware commented Jan 5, 2023

Hello. Please add support to serialize model to support REST API in Django. Something like django-phonenumber-field package. It would be very nice if it has the ability to serialize data out of the box without implement it manually to API view endpoint

@banagale
Copy link
Collaborator

banagale commented Jan 6, 2023

Thanks for the request.

Here's a direct link to the PhoneNumberField serializer field docs

@kiraware
Copy link
Author

kiraware commented Jan 7, 2023

Thanks for your response!

@kiraware
Copy link
Author

kiraware commented Jan 7, 2023

Also i wanna suggest that AddressField model look something like openid connect address claim, may have a look at https://openid.net/specs/openid-connect-core-1_0.html#AddressClaim Thanks again @banagale

@odin1in
Copy link

odin1in commented Jul 12, 2023

I use this monky patch for my project.

class AddressField(serializers.CharField):

    def to_representation(self, instance):
        data = {}
        data['raw'] = instance.raw 
        data['street_number'] = instance.street_number 
        data['route'] = instance.route 
        data['latitude'] = instance.latitude 
        data['longitude'] = instance.longitude

        if instance.locality:
            data['locality'] = instance.locality.name
            data['postal_code'] = instance.locality.postal_code
            if instance.locality.state:
                data['state'] = instance.locality.state.name
                data['state_code'] = instance.locality.state.code
                if instance.locality.state.country:
                    data['country'] = instance.locality.state.country.name
                    data['country_code'] = instance.locality.state.country.code

        return data

    def to_internal_value(self, data):
        return parse_address(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants