'django rest framework returning list instead of dict after serializering data
I am returning some data but instead of dict I am getting list in return
my serializer.py
file
class CommitteeDetailsSerializer(serializers.ModelSerializer):
class Meta:
model = Committee
fields = ['id','com_name', 'com_members_limit', 'com_amount_per_month',
'com_starting_date', 'com_join_id', 'com_status']
my views.py
serializer = CommitteeDetailsSerializer(get_committee, many=True)
I am getting this data list
{
"status": "success",
"msg": "Done.",
"data": [
{
"id": 19,
"com_name": "My second Committee",
"com_members_limit": 4,
"com_amount_per_month": 1000,
"com_starting_date": "2022-05-04",
"com_join_id": "GR9PKKOX65",
"com_status": "pending"
}
]
}
what I want is dict here in data {}
Solution 1:[1]
In your views.py in the serializer you passed many=True, hence its returning a list. Remove that and you should get one single object serialized instead of a list.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Uzzal H. Mohammad |