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

Home Posts Topics Members FAQ

Can Help me with this Search Function? Help!

88 New Member
hi

currently i am doing this search function for car booking website. it can search through either car seats or CarModel. it seems it able to do search function, however i small problem occurs to me. As i would also like to show the customer whether the car is available or not available. Basically it is car status at the moment. However, i am not sure how to do this. my ideas is that if car_inventory>0 , show available, otherwise show Not available. but seems can not work in my template which is my search.html. what is the correct syntax and it is possible for me not do in template but do function...my code for this function is

[code=python]

def search(request) :
myData = []
result1= []
result2= []
Qstring =[]
totalCarseats = []
totalCarmodel = []
Login = False
searchByseats = 0
searchBymodel = 0

if request.user.is _authenticated( ):

Login = True

if request.method == "POST":

myData = request.POST.co py()

Qstring = myData['search']

if request.has_key ('seats'):
searchByseats = 1
searchBymodel = 2
result1 = CarModel.object s.filter(seats_ _istartswith = Qstring).order_ by('seats')
print result1
totalCarseats = CarModel.object s.all().count()
if request.has_key ('model'):
searchByseats = 1
searchBymodel = 2
result2 = CarModel.object s.filter(car_mo del_code__istar tswith = Qstring ).order_by('car _model_code')
totalCarmodel = CarModel.object s.all().count()

return render_to_respo nse('search.htm l',{'result1':r esult1,'result2 ':result2,'SR': Qstring, 'searchByseats' :searchByseats, 'searchBymodel' :searchBymodel, 'Login':Login,' totalCarseats': totalCarseats,' totalCarmodel': totalCarmodel})

the man part of my template for search.html is( only for result1 which is search by car seats, as the same concept will be applied to result2 which is search by car model:
Expand|Select|Wrap|Line Numbers
  1. {% if result1 %}
  2.     <th><b>Car Seats</b></th>
  3.     <table border =1>
  4.     <tr>
  5.     <td>Car model</td>
  6.     <td>Car Description</td>
  7.     <td>Booking Price(SGD$)</td>
  8.     <td>Car Seats</td>
  9.     <td>Car Status</td>
  10.     <td>Rate Per Mileage</td>
  11.     <td>Photo</td>
  12.  
  13.     </tr>
  14.     {% for a in result1 %}
  15.         <tr>
  16.         <td>{{a.car_model_name }}</td>
  17.         <td>{{a.car_description }}</td>
  18.         <td>{{a.booking_price}}</td>
  19.         {% if {{a.car_inventory>0}} %}
  20.             <td>Available</td>
  21.         {%else%}
  22.             <td>Not Available</td>
  23.         <td>{{a.seats}}</td>
  24.         <td>{{a.ratePerMileage}}</td>
  25.         <td><img src ="{{a.get_carshot_url}}" width="150" height="150"></td>
  26.  
  27.  
  28.         </tr>
  29.     {% endfor %}
  30.  
  31.     </table>
  32.  
  33.  
  34. {% endif %}
  35.  
  36.  
it is a bit urgent at the moment, thanks for any kind help in advance!! :)
Dec 24 '07 #1
0 1421

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

Similar topics

3
2210
by: Liz Malcolm | last post by:
Hello and TIA for guidance. I am building a reusable search procedure (thanks go to Graham Thorpe for his example that set me on my way). Everything works up until the 2nd match is found, the command doesn't go to the third match, it exits out of the loop. I've read everything I could find in NG's, but I can't figure out where I'm going wrong. Here is my code. Function cmdSearch(ctlSearchText As Control, ctlFoundText As Control,...
83
7805
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face some other ploblems which i can not correct.I would appreciated if someone take a look at my programm so as to help me.I tried many times to find out where my mistakes are but i didn't manage something. I have made some comments due to the programm...
1
1949
by: midnightblue | last post by:
Please could someone help me. I am a relative newbie, and have the following function on my php search page on my Joomla! site. <?php } } function showSearchForm($dropListsArray,$config,$items,$pageNav,$fieldData,$searchString,$catid,$total,$phrase,$res) { global $mosConfig_live_site,$mosConfig_absolute_path,$my; if(!$searchString) $String = 'Search...'; else
22
3253
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of seats as 0 and the flight no. is also repeating. If any can tell why is this please help me. #include<stdio.h> #include<ctype.h> #include<conio.h>
0
8385
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
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
8602
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...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.