Я создаю фильтр ключевых слов в django
Мои 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)
Я заполняю значение формы в шаблоне
{% 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 %}
например, там 03 варианта
-Все
-TDO
-STU
Я щелкнул TDO и нажимаю кнопку «Фильтр», после чего он не запоминает мои выбранные параметры (TDO)
И это URL после нажатия на фильтр
show/?customer_type=TDO
Кто-нибудь здесь может узнать, в чем мои проблемы. Что я не так сделал