473,324 Members | 2,400 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,324 software developers and data experts.

how to express " if Not exist" concept in python

hi, currently i am doing booking car online and one of the function is cancel and update booking. if the booking number users entered in is not exist. it will redirect the page stating that the booking number did not exist or you never book with us. however. i would like to express this "if Not exist" concept in my coding. how should i achieve this. the following is my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. def deleteCar(request):
  3.  
  4.     if request.user.is_authenticated():
  5.  
  6.         Login = True
  7.         myId=request.session['B_id']
  8.         my = Booking1.objects.get(id= myId)
  9.  
  10.             IF NOT EXIST my:
  11.                         return HttpResponseRedirect ("/nobooking/")
  12.         else:
  13.                         dateStr=my.booking_time
  14.                 now=datetime.datetime.now()
  15.  
  16.                 print now
  17.                 one_day=60*60*24
  18.                 diff=comp_dates(dateStr,str(now).split('.')[0])
  19.                 print diff
  20.  
  21.         if diff > one_day:
  22.             return HttpResponseRedirect ("/unable/")
  23.  
  24.         if diff < one_day:
  25.             my.delete()
  26.         else:
  27.             return HttpResponseRedirect ("/Deny/")
  28.  
  29.     return render_to_response('confirmed_cancel.html')
  30.  
the IF NOT EXIST is just my concept in the coding, can any one help me with code..thanks so much. ;)
Dec 20 '07 #1
3 20752
dazzler
75
I'm not an expert and don't know what that Booking1.objects.get(id= myId) do , but can you search it first and check if it exist? In my code I have used sometimes try, expect in some places, it raises error if something doesn't exist (if for example trying to modify some variable that doesn't exist)
Dec 20 '07 #2
I'm not an expert and don't know what that Booking1.objects.get(id= myId) do , but can you search it first and check if it exist? In my code I have used sometimes try, expect in some places, it raises error if something doesn't exist (if for example trying to modify some variable that doesn't exist)
i am using Django framework, Booking1.objects.get(id= myId) what this code do is the same as SQL select statement where id is equal to myId which is post over from previous page. yes, i have tried this if not exist phrase before i post this question in forum and it returns me invalid syntax. thanks for your kind reply as well.
Dec 20 '07 #3
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. >>> obj = None
  2. >>> print obj
  3. None
  4. >>> if not obj:
  5. ...     print "Object 'obj' evaluates to 'None'"
  6. ...     
  7. Object 'obj' evaluates to 'None'
  8. >>> obj = ""
  9. >>> if not obj:
  10. ...     print "Object 'obj' evaluates to 'None'"
  11. ...     
  12. Object 'obj' evaluates to 'None'
  13. >>> obj = []
  14. >>> if not obj:
  15. ...     print "Object 'obj' evaluates to 'None'"
  16. ...     
  17. Object 'obj' evaluates to 'None'
  18. >>> obj = {}
  19. >>> if not obj:
  20. ...     print "Object 'obj' evaluates to 'None'"
  21. ...     
  22. Object 'obj' evaluates to 'None'
  23. >>> 
This is a very basic concept.
Dec 20 '07 #4

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

Similar topics

0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
0
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
0
by: sasha | last post by:
Hi All How we can access "Outlook Express". The senerio is: An ASPX file (in C#) should retrieve the contact info from "Outlook express" adress book. Any help appreciated. Thanks
2
by: Brian | last post by:
Hello, Can someone tell me a little bit about the upcoming Visual Basic .net 2005 Express and web development programs? Will there also be a "full" version of VB.NET 2005 that is not part of the...
1
by: sck10 | last post by:
Hello I am using Visual Web Developer 2005 Express. Whenever I use the "copy web site" function, it creates a "publishform" button on my task bar that doesn't go away. So if I publish 3...
8
by: olrt | last post by:
Hello, I plan to install Visual C# 2005 Express. I need a source code control system. It seems that there's no express version of Visual Source Safe. What should I do ? Is Visual C# 2005 Express...
11
by: kimiraikkonen | last post by:
Hello, I'm very new to C# and just installed VC# 2005 express edition and i have VB 2005 express installed previously. But i saw a thing which may be called as a "Visual C# 2005 express" bug? ...
4
by: kang jia | last post by:
hi currently i am getting an array from database,the code is in the following, if id do not exist variable b will render an empty array. at this time, i would like to check if this array is empty...
3
by: moltendorf | last post by:
I copied the files from my "test" database on my old server (MySQL was not running) to my new server ("./mysql/data/test" folder), and after starting the server, SHOW TABLES; shows all of the tables...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.