How to get all instances in serializer method field
I have a serializer method field and I am passing list data in the form of context to serializer like below.
name_list = [ "abc", "def",....]
obj_list = abc.objects.all()
Serializer = abcSerializer (obj_list, context=name_list, many=True)
class abcSerializer (serializers.ModelSerializer):
xyz = serializers.SerializerMethodField ("getXYZ", read_only=True)
class Meta:
model = abc
def getXYZ (self, data):
# here I want all instanceses, but I got only one instance in data.
I want to attach name_list data one by one to instace data with same index? How I can get all instanceses in my serializer method field?