get_a_room/rooms/models.py
def clean(self):
        """
        Checks if the values of a new booking are valid
        """
        if self.start_date > self.end_date:
            raise serializers.ValidationError(
                "Start date cannot be after end date!")

        if self.start_date < datetime.datetime.now().date():
            raise serializers.ValidationError(
                "Start date cannot be in the past!")

        if self.start_time > self.end_time:
            raise serializers.ValidationError(
                "Start time cannot be after end time!")

        if self.start_date == self.end_date:
            start_day_of_week = self.start_date.weekday()
            day_name = my_fields.DAYS_OF_THE_WEEK[start_day_of_week]
            if day_name[0] != self.day_of_week:
                raise serializers.ValidationError(
                    "Day of week does not match given dates")

        else:
            flag = False
            date_iter = self.start_date
            max_iter_date = self.start_date + datetime.timedelta(6)
            while date_iter <= self.end_date and date_iter <= max_iter_date:
                day = my_fields.DAYS_OF_THE_WEEK[date_iter.weekday()]
                if day[0] == self.day_of_week:
                    flag = True
                    break
                date_iter = date_iter + datetime.timedelta(1)

            if not flag:
                raise serializers.ValidationError(
                    "Day of week does not match given dates")

        Checks if the values of a new booking are valid
        
Checks if the values of a new booking are valid
Checks if the values of a new booking are valid
def clean(self):
        if self.start_date > self.end_date:
            raise serializers.ValidationError(
                "Start date cannot be after end date!")
        if self.start_date < datetime.datetime.now().date():
            raise serializers.ValidationError(
                "Start date cannot be in the past!")
        if self.start_time > self.end_time:
            raise serializers.ValidationError(
                "Start time cannot be after end time!")
        if self.start_date == self.end_date:
            start_day_of_week = self.start_date.weekday()
            day_name = my_fields.DAYS_OF_THE_WEEK[start_day_of_week]
            if day_name[0] != self.day_of_week:
                raise serializers.ValidationError(
                    "Day of week does not match given dates")
        else:
            flag = False
            date_iter = self.start_date
            max_iter_date = self.start_date + datetime.timedelta(6)
            while date_iter <= self.end_date and date_iter <= max_iter_date:
                day = my_fields.DAYS_OF_THE_WEEK[date_iter.weekday()]
                if day[0] == self.day_of_week:
                    flag = True
                    break
                date_iter = date_iter + datetime.timedelta(1)
            if not flag:
                raise serializers.ValidationError(
                    "Day of week does not match given dates")
def clean ( self ) : if self . start_date > self . end_date : raise serializers . ValidationError ( "Start date cannot be after end date!" ) if self . start_date < datetime . datetime . now ( ) . date ( ) : raise serializers . ValidationError ( "Start date cannot be in the past!" ) if self . start_time > self . end_time : raise serializers . ValidationError ( "Start time cannot be after end time!" ) if self . start_date == self . end_date : start_day_of_week = self . start_date . weekday ( ) day_name = my_fields . DAYS_OF_THE_WEEK [ start_day_of_week ] if day_name [ 0 ] != self . day_of_week : raise serializers . ValidationError ( "Day of week does not match given dates" ) else : flag = False date_iter = self . start_date max_iter_date = self . start_date + datetime . timedelta ( 6 ) while date_iter <= self . end_date and date_iter <= max_iter_date : day = my_fields . DAYS_OF_THE_WEEK [ date_iter . weekday ( ) ] if day [ 0 ] == self . day_of_week : flag = True break date_iter = date_iter + datetime . timedelta ( 1 ) if not flag : raise serializers . ValidationError ( "Day of week does not match given dates" )
Checks if the values of a new booking are valid
Checks if the values of a new booking are valid
"""
        Checks if the values of a new booking are valid
        """
self