473,405 Members | 2,379 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,405 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 1413

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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
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,...
0
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,...
0
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...
0
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,...
0
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...

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.