hi i am doing search function currently and its function should be correct, however, in my search.html i would like to go through a for loop and if inventory is bigger than zero, it will display available, otherwise, it will display " not available". however, i think my syntax for if statement got error, can anyone help me with this.
my search 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('sea ts')
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})
[/code]
the main part which i would like to seek for help is in my template which is search.html
[code=python]
{% 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 Status</td>
<td>Car Seats</td>
<td>Rate Per Mileage</td>
<td>Photo</td>
</tr>
{% for a in result1 %}
<tr>
<td>{{a.car_mod el_name }}</td>
<td>{{a.car_des cription }}</td>
<td>{{a.booking _price}}</td>
{% if {{a.booking_pri ce}} %}
<td>Available </td>
{% else %}
<td>Not Available</td>
<td>{{a.seats}} </td>
<td>{{a.ratePer Mileage}}</td>
<td><img src ="{{a.get_carsh ot_url}}" width="150" height="150"></td>
[/code]
PS. i am using Django framework which is based on python programming language thus the logic and syntax almost the same.thanks for any kind help :)
my search 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('sea ts')
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})
[/code]
the main part which i would like to seek for help is in my template which is search.html
[code=python]
{% 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 Status</td>
<td>Car Seats</td>
<td>Rate Per Mileage</td>
<td>Photo</td>
</tr>
{% for a in result1 %}
<tr>
<td>{{a.car_mod el_name }}</td>
<td>{{a.car_des cription }}</td>
<td>{{a.booking _price}}</td>
{% if {{a.booking_pri ce}} %}
<td>Available </td>
{% else %}
<td>Not Available</td>
<td>{{a.seats}} </td>
<td>{{a.ratePer Mileage}}</td>
<td><img src ="{{a.get_carsh ot_url}}" width="150" height="150"></td>
[/code]
PS. i am using Django framework which is based on python programming language thus the logic and syntax almost the same.thanks for any kind help :)