1
我喜歡DRF設置,它接收json中的數據並將其存儲在django中。串行是繼Django Rest Framework - 使用序列化程序發送json請求庫
class ReservationSerializer(serializers.ModelSerializer):
room = RoomSerializer()
reserved_days = DaySerializer(many=True)
additional_services = AdditionalServicesSerializer(many=True)
class Meta:
model = Reservation
fields = [
'start',
'end',
'check_in_time',
'check_out_time',
'reserved_days',
'additional_services',
'room',
'has_refund',
'payed',
'guest_name',
'reservation_number',
]
我可以用這個序列化準備在JSON模型,然後用Requests
庫發送此JSON?
不適用於傳遞和驗證數據。但如果將my_objects直接傳遞給序列化程序而沒有數據驗證,則可行 –