Пример #1
0
 def put(self, request, pk, format=None):
     reservation = self.get_object(pk)
     serializer = ReservationSerializer(reservation, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
 def post(self, req, format=None):
     fileData = req.FILES['invitationsFile']
     if not fileData.name.endswith('.csv'):
         return Response({"detail": "Not format accepted"},
                         status=status.HTTP_400_BAD_REQUEST)
     file_data = fileData.read().decode("utf-8")
     lines = file_data.split("\n")
     lst = []
     for line in lines:
         row = line.split(",")
         if (len(row) == 5):
             sData = {
                 "firstName":
                 row[0],
                 "lastName":
                 row[1],
                 "startTime":
                 datetime.datetime.strptime(row[2], '%m/%d/%y %I:%M %p'),
                 "endTime":
                 datetime.datetime.strptime(row[3], '%m/%d/%y %I:%M %p'),
                 "seats":
                 row[4]
             }
             s = ReservationSerializer(data=sData)
             if s.is_valid():
                 s.save()
                 lst.append(s.data)
     return Response(lst, status=status.HTTP_201_CREATED)
Пример #3
0
	def post(self, request, format=None):
		data = request.data
		serializer = ReservationSerializer(data=data)
		companions = data['companion']
		##validate을 할 때 serializer의 모든 field를 확인하는데 pop을 하면 companion 이 없어지니까 validation_error가 자꾸 뜬것....
		if serializer.is_valid():
			reservation = serializer.save()
			for companion in companions:
			##대신 여기서 객체로 넣어주는게 맞음 
				c = User.objects.get(pk=companion)
				reservation.companion.add(c)
			reservation.save()
			return Response(serializer.data, status=status.HTTP_201_CREATED)
Пример #4
0
 def post(self, request, format=None):
     serializer = ReservationSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)