2π
β
Itβs feasible, if you see the need. Although, the JSON encoding is done in the Response object, which is a full HTTPResponse subclass, so you would need to encode your own data:
import json
import requests
my_objects = Reservation.objects.all()
serializer = ReservationSerializer(data=my_objects, many=True)
if serializer.is_valid():
# now you do your encoding:
encoded_data = json.dumps(serializer.data)
response = requests.post(your_url,
headers={'Content-Type': 'application/json'},
data=encoded_data)
π€fixmycode
Source:stackexchange.com