How to alter the values of specific fields in HTML display form?

75 views
Skip to first unread message

Manish Shah

unread,
Apr 7, 2021, 5:13:24 AM4/7/21
to Django REST framework
I am having a nested serializer as:-
```
class DeviceConfigSerializer(serializers.ModelSerializer):
    config = serializers.JSONField()
    context = serializers.JSONField()

    class Meta:
        model = Config
        fields = ['backend', 'status', 'templates', 'context', 'config']


class DeviceDetailSerializer(serializers.ModelSerializer):
    config = DeviceConfigSerializer()

    class Meta(BaseMeta):
        model = Device
        fields = [
            'id',
            'name',
            'organization',
            'mac_address',
            'key',
            'last_ip',
            'management_ip',
            'model',
            'os',
            'system',
            'notes',
            'config',
        ]
   def update():
   ...
   ...
   ...

```
views:-
```
class DeviceDetailView(RetrieveUpdateDestroyAPIView):
    serializer_class = DeviceDetailSerializer
    queryset = Device.objects.all()
```

When I try to get the data, I receive this:-
Onsa2.png

But The data found in the HTML display form fields for the nested fields is not satisfactory:-
KJfVm.png

Can anyone help me with this?
PS: I have tried `to_represenation` and `to_internal_value` but that comes with it's problem.

Manish Shah

unread,
Aug 3, 2021, 11:21:23 PM8/3/21
to Django REST framework
The above problem gets resolved with the latest release of DRF i.e., ~3.12.0

It is mentioned about this issue in the first line itself here 3.12 Announcement

PS: Posting it here so that, if someone faces this issues, can find this useful.

Kind Regards, 
Manish
Reply all
Reply to author
Forward
0 new messages