[Answered ]-How to write DRF serializers for the desired output?

1👍

You can proceed this way

class TaskSerializer(ModelSerializer):
      class Meta:
            model=Task
            fields = '__all__'
class UserTaskSerializer(ModelSerialzier):
       id = serializer.CharField(source ='user.id')
       name = serializer.CharField(source ='user.username') # might be username,fullname or name only change in your own way
       task = TaskSerializer(many=true)
       class Meta:
            model=UserTask
            fields = ('id','name','task')

Just make sure you are using many=True in your view for UserSerializer class

Leave a comment