471,325 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

how to do if statement in Template??

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:
Expand|Select|Wrap|Line Numbers
  1. def search(request):
  2.     myData = []
  3.     result1= []
  4.     result2= []
  5.     Qstring =[]
  6.     totalCarseats = []
  7.     totalCarmodel = []
  8.     Login = False
  9.     searchByseats = 0
  10.     searchBymodel = 0
  11.  
  12.     if request.user.is_authenticated():
  13.  
  14.         Login = True
  15.  
  16.     if request.method == "POST":
  17.  
  18.         myData = request.POST.copy()
  19.  
  20.         Qstring = myData['search']
  21.  
  22.         if request.has_key('seats'):
  23.             searchByseats = 1
  24.             searchBymodel = 2
  25.             result1  = CarModel.objects.filter(seats__istartswith = Qstring ).order_by('seats')    
  26.             print result1
  27.             totalCarseats = CarModel.objects.all().count()
  28.         if request.has_key('model'):
  29.             searchByseats = 1
  30.             searchBymodel = 2
  31.             result2 = CarModel.objects.filter(car_model_code__istartswith = Qstring ).order_by('car_model_code')
  32.             totalCarmodel = CarModel.objects.all().count()
  33.  
  34.     return render_to_response('search.html',{'result1':result1,'result2':result2,'SR':Qstring, 'searchByseats':searchByseats, 'searchBymodel':searchBymodel,'Login':Login,'totalCarseats':totalCarseats,'totalCarmodel':totalCarmodel})
  35.  
the main part which i would like to seek for help is in my template which is search.html
Expand|Select|Wrap|Line Numbers
  1.  
  2. {% if result1 %}
  3.     <th><b>Car Seats</b></th>
  4.     <table border =1>
  5.     <tr>
  6.     <td>Car model</td>
  7.     <td>Car Description</td>
  8.     <td>Booking Price(SGD$)</td>
  9.     <td>Car Status</td>
  10.     <td>Car Seats</td>
  11.     <td>Rate Per Mileage</td>
  12.     <td>Photo</td>
  13.  
  14.     </tr>
  15.     {% for a in result1 %}
  16.         <tr>
  17.         <td>{{a.car_model_name }}</td>
  18.         <td>{{a.car_description }}</td>
  19.         <td>{{a.booking_price}}</td>
  20.         {% if {{a.booking_price}} %}
  21.         <td>Available</td>
  22.         {% else %}
  23.         <td>Not Available</td>
  24.         <td>{{a.seats}}</td>
  25.         <td>{{a.ratePerMileage}}</td>
  26.         <td><img src ="{{a.get_carshot_url}}" width="150" height="150"></td>
  27.  
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 :)
Dec 23 '07 #1
0 847

Post your reply

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

Similar topics

1 post views Thread by Keith Davies | last post: by
3 posts views Thread by sck10 | last post: by
reply views Thread by rosydwin | 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.