动态地过滤表单中的内容django

时间:2014-03-06 16:00:53

标签: javascript jquery django django-templates django-views

view.py

def total_rent(request):
    context = RequestContext(request)
    venues = Venue.objects.all()
    places = Venue.objects.values_list('place', flat=True).distinct()
    context1 = ({'venues': venues, 'places': places})
    total = request.GET.get('venue')
    context1.update({'total': total})
    return render_to_response("test3.html", context1, context)

test3.html

<form action="" method="get">
    <select name="pl">
        <option selected="selected" disabled>---------</option>
        {% for place in places %}
            <option value="{{ place }}">{{ place }}</option>
        {% endfor%}
    </select>
    <input type="button" value="filter" />
    {% for venue in venues %}
        <input type="radio" name="venue" id="venue{{ forloop.counter }}" value="{{ venue.rent }}">
        <label for="venue{{ forloop.counter }}"></label>
        {{venue.venue_Name}}        
        {{ venue.place }}parking:{{ venue.parking_area }}
        Rs {{ venue.rent }}     
    {% endfor %}
    <input type="submit" value="service" />
</form>

我希望在我选择下方菜单中的位置并按下按钮过滤内容时过滤场地

1 个答案:

答案 0 :(得分:0)

你必须编写一个ajax函数来检索场地。调用ajax函数jquery onchange选择标记的地方。