473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to correctly nest if statement into for loop?

hi, currently i am doing a car rental website, once it is bigger tthan 1 day's time which is 24 hours, its inventory will be updated and only admin can executed this. However if it is smaller than 24 hours, then it will still remain at the current inventory. the car's booking time is inside my Booking1 table and car_inventory is inside CarModel table.
Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.booking_time
  7.         t=str(invtime).split('.')[0]
  8.         now=datetime.datetime.now()
  9.         one_day=60*60*24
  10.         diff=comp_dates(t,str(now).split('.')[0])
  11.         print diff
  12.         if diff>one_day:
  13.             for a in CarModel.objects.all():    
  14.                 qtyInStock=a.car_inventory
  15.                 orderQuantity = 1
  16.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  17.                 a.car_inventory=qtyLeft
  18.                 a.save()
  19.                 allObj=CarModel.objects.all()
  20.                 print allObj
  21.                 print "LLLLLLLLLLLLLLLLLL"
  22.         return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  23.         if not diff>one_day:
  24.             return render_to_response("inventory.html")
  25.  
as for this code, it don not error but i never go through my if not condition even through it fulfills this condition. can anyone help me with this, thus it will go through this "if not diff>one_day:" condition.thanks so much for kind help :)
Dec 21 '07 #1
3 1604
dazzler
75
have you tried using if diff<one_day: ? :D

or what about:
Expand|Select|Wrap|Line Numbers
  1. if diff>one_day:
  2. #something
  3. else:
  4. #something
Dec 21 '07 #2
dazzler
75
hmmh, should this "return render_to_response("inventoryupdate.html", {'allObj':allObj})" be inside of your first if statement? because now it isn't
Dec 21 '07 #3
hmmh, should this "return render_to_response("inventoryupdate.html", {'allObj':allObj})" be inside of your first if statement? because now it isn't

thanks for your kind help, in that scenario it works according to your way, but one thing i do not understand is that why everytime it will go to updateinventory page even the content has changed to inventory page.it seems quite strange to me. i mean how the updateinventory page knows inventory pages' content??Although it works in the way i want yet i do not understand its logic..hmm, if possible, can explain this to me, thanks so much.:)

however, i would like to ask you about one more scenario.in fact, it is the same logic but did not work in the other part of my coding. the coding is in the following:

Expand|Select|Wrap|Line Numbers
  1. def confirmUp(request):
  2.     Array=[]
  3.     ba={}
  4.     q=request.session['BK_id']
  5.     uID=request.user.id
  6.     #ba=Booking1.objects.get(id=q)
  7.     #print ba.id
  8.  
  9.     for i in Booking1.objects.all():
  10.  
  11.         if  i.id == q:
  12.             print "PPPPPPPPP"
  13.             ba=Booking1.objects.get(id=q) 
  14.             print "LLLLLLLLLLLLLLLL"
  15.             Array.append(ba)
  16.             return render_to_response('proceed.html',{'Array': Array })
  17.  
  18.         else:
  19.             return HttpResponseRedirect("/Notexist/")    
  20.  
it seems never go into if statement even the condition is fulfilled at "if i.id == q:"
thanks for your kind help :)
Dec 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gregor Lingl | last post by:
I'm working on a windows machine I've written a Tkinter-app (sort of game) which consists mainly of an animation which is driven by a while True: ... loop. If I close the App's window by...
9
by: Ben | last post by:
I have two 'Do While Not' statements, that are getting information from the same recordset. If I comment out the first one I can get the results for the second one, and vice-versa. Why is this...
10
by: ale.of.ginger | last post by:
Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has...
15
by: Jens.Toerring | last post by:
Hi, I have a possibly rather stupid question about the order of evaluation in a statement like this: result = foo( x ) - bar( y ); How can I make 100% sure that foo(x) is evaluated before...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
4
by: Dave | last post by:
If so, what is wrong with this code in APS 3.0? I open a recordset with order info. Each record contains the order header info plus a line item from the order detail. So the recordset looks...
2
by: Jon Turlington | last post by:
When in access the SQL Statement works as expected; in ADO it does not. I have replaced the * with the % so I am sure that's not the problem. Anyone have any idea? <% Dim objConn, objRS,...
3
by: Steven Nagy | last post by:
Hi all, ASP.NET : Framework 2.0 - C# A recent addition to my code generater will create GridView's and ObjectDataSource's in a control (ASCX). So the code gen creates an ascx, ascx.cs,...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
2
kmartinenko
by: kmartinenko | last post by:
Hi, I am very new to Python and I would like to know if it is possible to nest 'for' statements? The question precipitates from a certain problem I am having with running a simple calculation...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.