I have a custom apiview
to query item in cart. I got a instance but when i return response
it display error like this:
Object of type Order is not JSON serializable
my views.py:
class getCart(APIView):
def get(self, request, format=None):
try:
order = Order.objects.get(user=request.user, confirm=False)
except Order.DoesNotExist:
order = Order(user=request.user, confirm=false)
order.save()
return Response(order)
So, you have to convert your model instance into json, in DRF it is done through Serializer
As it is specific to model so I am using ModelSerializer
You can refer from here:- https://www.django-rest-framework.org/api-guide/serializers/#modelserializer