mercredi 4 novembre 2015

Django won't go into my if statement

I've fairly new to django and am having trouble with if statements. For the following code if I change the operand sign around it gives me the results that I want but otherwise it won't work even if I put an else statement after it I find that both my if and else gives the same results:

Output: 
checkin = 2015-12-24
stay_nights = 4

Rates table output: minimum start end 1 2015-11-05 2015-12-25 5 2015-12-26 2015-12-30 1 2015-12-31 2016-03-31

  • Should stay overlap a minimum night stay period and should the remainder of the total stay be less than the minimum nights required then this shouldn’t allow for save as it will not be confirmed by resort.

Example: Booking a 4 night stay from the 24th of December should not allow service to be saved as remainder of nights from 26th December is 2 nights as required minimum night stay from the 26th is 5 nights.

  • Should stay overlap a minimum night stay period and should the remainder of the total stay be equal to or more than the minimum nights required then this should allow for save as it will be confirmed by resort. Example; Booking a 7night stay from the 24th of December should allow service to be saved as remainder of nights from 26th December is 5N which is within the minimum number of nights required.

    aa = Rate.objects.get(start__lte=checkin, end__gte=checkin, object_id=room.id)

                    if stay_nights >= aa.minimum:
                        raise Exception('stay nights 1: %s minimum nights 1: %s' % (stay_nights, aa. minimum))
                    else:
                        if stay_nights < aa. minimum:
                            raise Exception('stay nights 2: %s minimum nights 2: %s' % (stay_nights, aa. minimum))
    
    

Aucun commentaire:

Enregistrer un commentaire