0
créer un filtre mot-clé dans djangooption sélectionnée dans django choicefield dynamique
Mon 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
})
Mon 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)
Je POPULATE Thes valeur sous forme de modèle que
{% 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 %}
pour exa mple il 03 Options -Tous -TDO -STU J'ai cliqué TDO et je cliquez sur le bouton de filtre après qu'il est garde pas en mémoire les options seletected (TDO)
Et url après filtre est cliqué
show/?customer_type=TDO
Tout le monde ici peut savoir quel est mon problems.?What J'ai mal
merci pour votre aide. – kn3l