[Vuejs]-Update profile avatar DRF and Vue.js

0👍

Try to unindent the super call in your update method:

def update(self, instance, validated_data):
    parser_classes = (MultiPartParser)
    if 'profile' in validated_data:
        ...

    # unindented
    return super(UserSerializer, self).update(instance, validated_data)

EDIT:

ProfileSerializer should work correctly, although I am not sure about nested_serializer = self.fields['profile'] and updating a related instance through explicit .update(). Try rewriting your code to something like this:

if 'profile' in validated_data:
    nested_instance = instance.profile
    nested_data = validated_data.pop('profile')
    Profile.objects.filter(pk=nested_instance.pk).update(**nested_data)

If the problem remains, then recheck your request payload coming from front-end.

Leave a comment