You will need to loop over the response values using *map* and assign each
value to their designated form field.

On Tue, Aug 10, 2021 at 8:12 AM Manish Shah <[email protected]> wrote:

> Greetings everyone,
>
> I have these nested serializers, in which the fields are not appropriately
> maped to html form fields in default browsable API page of django
> rest_framework, I have customized the representation of the response, and
> now I want to map those values to the appropriate HTML form fields
>
> Below is my `serializer`
> ``` python
> from rest_framework_gis import serializers as gis_serializers
> from rest_framework import serializers
>
> class NestedtLocationSerializer(gis_serializers.GeoFeatureModelSerializer):
>     class Meta:
>         model = Location
>         geo_field = 'geometry'
>         fields = (
>             'type',
>             'is_mobile',
>             'name',
>             'address',
>             'geometry',
>         )
>
>
> class NestedFloorplanSerializer(serializers.ModelSerializer):
>     class Meta:
>         model = FloorPlan
>         fields = (
>             'floor',
>             'image',
>         )
>
>
> class DeviceLocationSerializer(serializers.ModelSerializer):
>     location = NestedtLocationSerializer()
>     floorplan = NestedFloorplanSerializer(required=False, allow_null=True)
>
>     class Meta:
>         model = DeviceLocation
>         fields = (
>             'location',
>             'floorplan',
>             'indoor',
>         )
> ```
>
> with the above serilaizers, I am getting this:-
> Response:-
> [image: NbOXd.png]
>
>
> But in the html form fields the values of `is_mobile`, `type`, `name` are
> not loading in the html form fields, (probably because the representation
> of the data has been customized):-
>
> [image: 5AtrZ.png]
>
> Is there any way, I can control the default mapping of these values to
> appropriate serializer fields to fill the values in the form in the
> django-rest-framework browsable page??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/100f6a81-6293-4937-8ffb-73dc81a72401n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/100f6a81-6293-4937-8ffb-73dc81a72401n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CACbngZdDXtAryTK5bdWtmMxP_YxYFi5oUr5hdRyOscUUTcEhvg%40mail.gmail.com.

Reply via email to