我有一些問題:
我使用Django的形式,領域,如MultipleChoiceField
在view.py我乾淨的數據,並獲取Get URL這樣
http://localhost:8000/?category=&style=&sex=&brand=ASICS&brand=Be+Positive&low_price=&high_price=
給我建議,我可以重新整理品牌領域並隱藏空洞。
我想要得到的東西是這樣的:對於forms.ModelMultipleChoiceFIeld裝飾GET URL中使用的形式
forms.py
如何設置空值(empty_label):
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() ]
http://localhost:8000/?brand=1+2
而且別的一個問題
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})
第一部分:我不喜歡我的網址的外觀如何看待我的網址 – JIoJIaJIu 2010-11-30 13:53:12