473,465 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to do if statement in Template??

88 New Member
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 903

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

Similar topics

2
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...
1
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...
4
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>: ...
10
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...
3
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...
7
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
9
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...
2
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...
10
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.