Can Help me with this Search Function? Help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

    Can Help me with this Search Function? Help!

    hi

    currently i am doing this search function for car booking website. it can search through either car seats or CarModel. it seems it able to do search function, however i small problem occurs to me. As i would also like to show the customer whether the car is available or not available. Basically it is car status at the moment. However, i am not sure how to do this. my ideas is that if car_inventory>0 , show available, otherwise show Not available. but seems can not work in my template which is my search.html. what is the correct syntax and it is possible for me not do in template but do function...my code for this 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('seats')
    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})

    the man part of my template for search.html is( only for result1 which is search by car seats, as the same concept will be applied to result2 which is search by car model:
    [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 Seats</td>
    <td>Car Status</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.car_invento ry>0}} %}
    <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>


    </tr>
    {% endfor %}

    </table>


    {% endif %}

    [/code]

    it is a bit urgent at the moment, thanks for any kind help in advance!! :)
Working...