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
- {% if result1 %}
- <th><b>Car Seats</b></th>
- <table border =1>
- <tr>
- <td>Car model</td>
- <td>Car Description</td>
- <td>Booking Price(SGD$)</td>
- <td>Car Seats</td>
- <td>Car Status</td>
- <td>Rate Per Mileage</td>
- <td>Photo</td>
- </tr>
- {% for a in result1 %}
- <tr>
- <td>{{a.car_model_name }}</td>
- <td>{{a.car_description }}</td>
- <td>{{a.booking_price}}</td>
- {% if {{a.car_inventory>0}} %}
- <td>Available</td>
- {%else%}
- <td>Not Available</td>
- <td>{{a.seats}}</td>
- <td>{{a.ratePerMileage}}</td>
- <td><img src ="{{a.get_carshot_url}}" width="150" height="150"></td>
- </tr>
- {% endfor %}
- </table>
- {% endif %}