Пример #1
0
    def create(self, request):

        newItinerary = Itinerary()
        newItinerary.starttime = request.data["starttime"]

        customer = Customer.objects.get(user=request.auth.user)
        newItinerary.customer = customer

        attraction = Attraction.objects.get(pk=request.data["attraction_id"])
        newItinerary.attraction = attraction

        newItinerary.save()

        serialize = ItinerarySerializer(newItinerary, context={"request":request})
        return Response(serialize.data)
Пример #2
0
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized Itinerary instance
        """
        newitinerary = Itinerary()
        newitinerary.attraction = request.data["attraction"]
        newitinerary.customer = request.data["customer"]
        newitinerary.starttime = request.data["starttime"]
        newitinerary.save()

        serializer = ItinerarySerializer(newitinerary, context={'request': request})

        return Response(serializer.data)
Пример #3
0
    def create(self, request):

        attraction = Attraction.objects.get(pk=request.data["ride_id"])
        customer = Customer.objects.get(user=request.auth.user)

        new_itinerary_item = Itinerary()
        new_itinerary_item.starttime = request.data["starttime"]
        new_itinerary_item.customer = customer
        new_itinerary_item.attraction = attraction

        new_itinerary_item.save()

        serializer = ItineraryItemSerializer(new_itinerary_item,
                                             context={'request': request})

        return Response(serializer.data)
Пример #4
0
    def create(self, request):
        """Handle POST operations
        Returns:
            Response -- JSON serialized itinerary instance
        """
        new_itinerary_item = Itinerary()
        new_itinerary_item.attraction = request.data["ride_id"]
        new_itinerary_item.customer_id = request.auth.user.customer.id
        new_itinerary_item.starttime = request.data["starttime"]

        new_itinerary_item.save()

        serializer = ItinerarySerializer(new_itinerary_item,
                                         context={'request': request})

        return Response(serializer.data)
Пример #5
0
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized Itinerary instance
        """
        newitem = Itinerary()
        newitem.starttime = request.data["starttime"]
        newitem.customer = Customer.objects.get(user=request.auth.user)
        newitem.attraction = Attraction.objects.get(pk=request.data["ride_id"])
        newitem.save()

        serializer = ItineraryItemSerializer(newitem,
                                             context={'request': request})

        return Response(serializer.data)
Пример #6
0
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized Itinerary Item instance
        """
# MAKE SURE YOU ARE ASSIGNING THE AREA OBJECT TO THE new_itenary.area property instead of just they FK value
        new_itinerary_item = Itinerary()
        new_itinerary_item.starttime = request.data["starttime"]
        new_itinerary_item.customer = Customer.objects.get(user=request.auth.user)
        new_itinerary_item.attraction = Attraction.objects.get(pk=request.data["ride_id"])

        new_itinerary_item.save()
# Saves the new thing to the DB in JSON
        serializer = ItineraryItemSerializer(new_itinerary_item, context={'request': request})

        return Response(serializer.data)
Пример #7
0
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized itinerary item instance
        """
        new_itinerary_item = Itinerary()
        # new_itinerary.name = request.data["name"]
        # had to import the model to utizlize the below
        new_itinerary_item.starttime = request.data["starttime"]
        new_itinerary_item.customer = Customer.objects.get(user=request.auth.user)
        new_itinerary_item.attraction = Attraction.objects.get(pk=request.data["ride_id"])

        new_itinerary_item.save()

        serializer = ItineraryItemSerializer(new_itinerary_item, context={'request': request})

        return Response(serializer.data)
Пример #8
0
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized Itinerary instance
        """
        customer = Customer.objects.get(user=request.auth.user)
        attraction = Attraction.objects.get(pk=request.data["attraction_id"])

        new_itinerary = Itinerary()
        new_itinerary.customer = customer
        new_itinerary.attraction = attraction
        new_itinerary.starttime = request.data["starttime"]

        new_itinerary.save()

        serializer = ItinerarySerializer(new_itinerary,
                                         context={'request': request})

        return Response(serializer.data)
Пример #9
0
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized Attraction instance
        """
        new_itinerary_item = Itinerary()
        new_itinerary_item.starttime = request.data["starttime"]
        # Wow! Django knows who the current user is, but we have to get the Customer
        new_itinerary_item.customer = Customer.objects.get(
            user=request.auth.user)
        new_itinerary_item.attraction = Attraction.objects.get(
            pk=request.data["ride_id"])

        new_itinerary_item.save()

        # change the thing we just saved to JSON
        # When instantiating a HyperlinkedModelSerializer you must include the current request in the serializer context. Doing so will ensure that the hyperlinks can include an appropriate hostname, so that the resulting representation uses fully qualified URLs, such as: http://api.example.com/accounts/1/
        serializer = ItinerarySerializer(new_itinerary_item,
                                         context={'request': request})

        return Response(serializer.data)