473,657 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to express " if Not exist" concept in python

88 New Member
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 20933
dazzler
75 New Member
I'm not an expert and don't know what that Booking1.object s.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
kang jia
88 New Member
I'm not an expert and don't know what that Booking1.object s.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.object s.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 Recognized Expert Moderator Specialist
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
10187
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 database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means "Specified partition does not exist". Does anybody know if it is a database problem or a problem of
0
2642
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). Since then, I found lots of the following in the postmaster output: 2003-11-29 15:19:54 ERROR: large object 4838779 does not exist 2003-11-29 15:20:11 ERROR: large object 4838779 does not exist
0
326
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
1072
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 visual studio suite? Just a little confused about all of the options. Thanks, Brian
1
1375
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 different times, it creates 3 "publishform" buttons. Do I need to re-install the application? -- Thanks in advance,
8
7048
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 "compatible" with open source CVS system ?? Thanks !! Olivier.
11
2025
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? For example, in VB 2005 express while i was coding, if there's a coding error, errors are displayed in error list below the screen immediately during coding and before starting debugging. But in VC# 2005 express, if there's a coding error,...
4
2380
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 means the id is not exist in my Booking1 table. How should i express this " if empty " concept in python? def confirmUp(request): q=request.session b=Booking1.objects.filter(id__exact=q) if b=empty
3
10358
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 that are supposed to be there, but running a SELECT * FROM `configuration`; (for example) returns "test.configuration does not exist). I've tried the following repair statement since I'm not too familiar with backing up and restoring data. ...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.