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
Source:stackexchange.com