472,995 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,995 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
  12.     if request.user.is_authenticated():
  14.         Login = True
  16.     if request.method == "POST":
  18.         myData = request.POST.copy()
  20.         Qstring = myData['search']
  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()
  34.     return render_to_response('search.html',{'result1':result1,'result2':result2,'SR':Qstring, 'searchByseats':searchByseats, 'searchBymodel':searchBymodel,'Login':Login,'totalCarseats':totalCarseats,'totalCarmodel':totalCarmodel})
the main part which i would like to seek for help is in my template which is search.html
Expand|Select|Wrap|Line Numbers
  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>
  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>
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 895

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

Similar topics

by: Gadrin77 | last post by:
as a newbie to XSL, is it possible to mimic a SELECT/CASE statement using XSL? I tried a quickie and I kept getting errors either using PARAM or WITH-PARAM in the wrong place or VARIABLE. I...
by: Keith Davies | last post by:
Hi All, I've got a document containing a internal lookups (I want to show a relationship hierarchy, starting at an arbitrary point, or series of points). It's easy if I know what item IDs I...
by: celerystick | last post by:
This is an xsl question, comp.infosystems.www.authoring.stylesheets were not able to help , here goes .... With one xml file containing repeated element <subject>: ...
by: SueB | last post by:
I currently have a 'mail-merge' process in my Access db project. It generates custom filled out Award Certificates based on an SQL SELECT statement in a VBA routine invoked by clicking on a...
by: sck10 | last post by:
Hello, I am trying to use an If Then statement inside of a repeater control. However, I am getting the following error: Expression expected. Any help would be appreciated. Thanks in...
by: VK | last post by:
Let's say I have a rather big HTML template like <?xml version="1.0" encoding="ISO-8859-1"?> .... <snip> .... <xsl:template match="/"> <html> <!-- ... A lot of HTML but no XSL so far
by: xmlhelp | last post by:
stuff.XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="uid"/> <xsl:template match="/"> parameter...
by: JRough | last post by:
I have this code that switches templates depending on if the user fills in a form with a request. The request asks for the $mark & $number. If that request gets input then it displays a list...
by: stewdizzle | last post by:
I am setting up a small site for personal use. It consists of a form that transfers inputed values to an html template. The ouput is code that i can use to quickly post on a website. In the...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.