Ich habe einige Frage:
ich django Form und Felder wie MultipleChoiceField
in view.py ich saubere Daten und bekommen URL GET wie diese
http://localhost:8000/?category=&style=&sex=&brand=ASICS&brand=Be+Positive&low_price=&high_price=
beraten Geben Sie mir, ich kann gruppiere Markenfeld und verstecke dich leer.
Ich möchte immer so etwas wie dieses:
http://localhost:8000/?brand=1+2Dekorieren GET URL Formulare mit
Und sonst eine Frage:
Wie kann ich leer Wert (empty_label) für forms.ModelMultipleChoiceFIeld
forms.py:
brand = forms.MultipleChoiceField(required=False,
widget=forms.SelectMultiple(attrs={'size':1})
)
def __init__(self,app_label=None, *args, **kwargs):
super(Search, self).__init__(*args, **kwargs)
self.fields['brand'].choices = [('', 'All brands')]+[(brand.name, brand) for brand in Brand.objects.all() ]
views.py:
if request.method == 'GET' and request.GET:
form = SearchForm(app_label, request.GET)
if form.is_valid():
brands = form.cleaned_data['brand']
kwargs.update({"brand__name__in": brands})
ersten Teil: Ich mochte nicht, wie sieht meine URL – JIoJIaJIu
Sekunde: für mich ist es wichtig, empty_label (das ist keine Bezeichnung als HTML-Label) für forms.ModelMultipleChoiceFIeld – JIoJIaJIu