tags:

views:

135

answers:

1

I create a keyword filter in django

My views.py

#..............
if request.method == 'POST':
                 form = FilterContentForm(request.POST)
        else:
                 form = FilterContentForm()
        if len(keyword_dict)!= 0 and keyword_dict['customer_type']:
            list_customer = filter(keyword_dict['customer_type'])
            print keyword_dict
            return render_to_response('customers_filter.html', {"customers":list_customer,
                                                                     "form":form
                                                                     })

My forms.py

#..............
CUSTOMER_TYPE_CHOICES = [('', 'All')] + [(customer_type.name, customer_type.name) for customer_type in Customer_Type.objects.all()]

class FilterContentForm(forms.Form):
    customer_type = forms.ChoiceField(choices=CUSTOMER_TYPE_CHOICES, required=False)  
    def __init__(self, *args, **kwargs):
        if 'label_suffix' not in kwargs:
            kwargs['label_suffix'] = ''
        super(FilterContentForm, self).__init__(*args, **kwargs)

I populate thes form value to template

{% extends "base.html" %}
{% block external %}
   <script type="text/javascript" src="/site_media/scripts/search.js"></script>
{% endblock %}

{% block content %}
{% block main %}
<form id="search-form" method="GET" action="." name="f">
{{ form.as_ul }}

<button id="filter">Filter</button>
</form>
<p>
<div id="search-results">
  {% if customers %}
   {% include 'customers.html' %}
  {% endif %}
</div>
{% endblock %}
{% endblock %}

for example there 03 options -All -TDO -STU I clicked TDO and I click Filter button after that it 's not remember my seletected options (TDO)

And it url after filter is clicked

show/?customer_type=TDO

Anybody here Can find out what is my problems.?What I have wrong

+1  A: 

html:

<form id="search-form" method="GET" action="." name="f">

view:

if request.method == 'POST':

So.. maybe you need method="POST" ?

Pydev UA
thank for your helping.
python