0
我在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
})
我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)
我填充THES形式值到模板
{% 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 exa mple有03選項 -All -TDO -STU 我點擊TDO和我點擊,它的不記得我seletected選項(TDO)
後過濾器按鈕,它過濾後的網址被點擊
show/?customer_type=TDO
這裏
任何人都可以找出哪些是我problems.?What我有錯
感謝您的幫助。 – kn3l 2009-12-22 02:51:06