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: -
-
def deleteCar(request):
-
-
if request.user.is_authenticated():
-
-
Login = True
-
myId=request.session['B_id']
-
my = Booking1.objects.get(id= myId)
-
-
IF NOT EXIST my:
-
return HttpResponseRedirect ("/nobooking/")
-
else:
-
dateStr=my.booking_time
-
now=datetime.datetime.now()
-
-
print now
-
one_day=60*60*24
-
diff=comp_dates(dateStr,str(now).split('.')[0])
-
print diff
-
-
if diff > one_day:
-
return HttpResponseRedirect ("/unable/")
-
-
if diff < one_day:
-
my.delete()
-
else:
-
return HttpResponseRedirect ("/Deny/")
-
-
return render_to_response('confirmed_cancel.html')
-
the IF NOT EXIST is just my concept in the coding, can any one help me with code..thanks so much. ;)
3 20933
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'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.
bvdet 2,851
Recognized Expert Moderator Specialist - >>> obj = None
-
>>> print obj
-
None
-
>>> if not obj:
-
... print "Object 'obj' evaluates to 'None'"
-
...
-
Object 'obj' evaluates to 'None'
-
>>> obj = ""
-
>>> if not obj:
-
... print "Object 'obj' evaluates to 'None'"
-
...
-
Object 'obj' evaluates to 'None'
-
>>> obj = []
-
>>> if not obj:
-
... print "Object 'obj' evaluates to 'None'"
-
...
-
Object 'obj' evaluates to 'None'
-
>>> obj = {}
-
>>> if not obj:
-
... print "Object 'obj' evaluates to 'None'"
-
...
-
Object 'obj' evaluates to 'None'
-
>>>
This is a very basic concept.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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
|
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
|
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,
| |
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.
|
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,...
|
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
|
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.
...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |