472,992 Members | 3,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 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 20521
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.