my search function is:
Expand|Select|Wrap|Line Numbers
- 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__istartswith = Qstring ).order_by('car_model_code')
- totalCarmodel = CarModel.objects.all().count()
- return render_to_response('search.html',{'result1':result1,'result2':result2,'SR':Qstring, 'searchByseats':searchByseats, 'searchBymodel':searchBymodel,'Login':Login,'totalCarseats':totalCarseats,'totalCarmodel':totalCarmodel})
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 Status</td>
- <td>Car Seats</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.booking_price}} %}
- <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>