Reputation: 119
I'm trying to get output result as an object but i'm getting result as a list.
My view:
def Expense_with_id(request, id):
details = ExSerializer(Cat.objects.filter(id=id).all(), many=True).data
return JsonResponse(details, safe=False)
Output:
[{
"id": 1,
"category": 1,
......
}]
I want my output to be :
Expected Output:
{
"id": 1,
"category": 1,
......
}
How can I achieve this with the current query.
Upvotes: 0
Views: 301
Reputation: 73
use get() when you want to get a single unique object, and filter() when you want to get all objects that match your lookup parameters.
Upvotes: 0
Reputation: 903
ExSerializer(Cat.objects.get(id=id))
You are doing filter()
instead of get()
.
Upvotes: 1