Пример #1
0
 def validate(self, data):
     """
     Check that start is before finish.
     """
     room = Room()
     room_value = room.get_value_by_id(
         data.get('room'),
         nested_id=data.get('hotel', {}).get("public_id")
     )
     if not room_value:
         raise serializers.ValidationError(
             {
                 'room': "room don't not exists"
             }
         )
     filter_rate = Rate.objects.filter(
         inventory__date=data.get('date'),
         room__public_id=data.get('room')
     )
     if filter_rate.exists():
         raise serializers.ValidationError(
             {
                 'date': (
                     'It already exists in the inventory in the room '
                     'on this date'
                 )
             }
         )
     data['room'] = room_value
     return data
Пример #2
0
    def get_object(self):
        """
        Returns the object the view is displaying.

        You may want to override this if you need to provide non-standard
        queryset lookups.  Eg if objects are referenced using multiple
        keyword arguments in the url conf.
        """
        hotel_id = self.kwargs.get('public_id')
        self.valid_hotel(hotel_id)
        room = Room()
        room_value = room.get_value_by_id(
            self.kwargs.get('room_id'),
            nested_id=hotel_id
        )
        if not room_value:
            self.base_value_not_found('room')
        return room_value