473,375 Members | 1,669 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,375 software developers and data experts.

Can Help me with this Search Function? Help!

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.copy()

Qstring = myData['search']

if request.has_key('seats'):
searchByseats = 1
searchBymodel = 2
result1 = CarModel.objects.filter(seats__istartswith = Qstring).order_by('seats')
print result1
totalCarseats = CarModel.objects.all().count()
if request.has_key('model'):
searchByseats = 1
searchBymodel = 2
result2 = CarModel.objects.filter(car_model_code__istartswit h = Qstring ).order_by('car_model_code')
totalCarmodel = CarModel.objects.all().count()

return render_to_response('search.html',{'result1':result 1,'result2':result2,'SR':Qstring, 'searchByseats':searchByseats, 'searchBymodel':searchBymodel,'Login':Login,'total Carseats':totalCarseats,'totalCarmodel':totalCarmo del})

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 1412

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

Similar topics

3
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...
83
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...
1
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...
22
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...
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...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.