472,146 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 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 1359

Post your reply

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

Similar topics

83 posts views Thread by deppy_3 | last post: by
22 posts views Thread by Amali | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.