2011-12-15 76 views
0

我有一個列a到f的表。在視圖中按值保存排序

我然後有一個整理箱,其排序列的通過按重量計,位置,眼睛的顏色等

重量,位置,眼睛的顏色等的每個f有的起始值,例如,無。

現在,您可以將值從None更改爲「50-100」,「Korea」,「Hazel」。

如果我想刷新頁面,或更改需要排序的列,我如何保持排序值從恢復到無。

繼承人的模板代碼的一個小例子:

<form action="" method="get"> 
<div class="sort"> 
<ul> 
    <li> 
    <a>Sort By</a> 
    </li> 
</ul>  
<ul> 
    <li id="sample4" class="dropdown4"> 
    <a href="#">Location | <span4>World Wide</span4></a> 

     <ul><li><a href="#"><input type="radio" id="radio4" name="Location" value="America"/><label for="radio4">America</label></a> 
       <a href="#"><input type="radio" id="radio5" name="Location" value="Zanzibar"/><label for="radio5">Zanzibar</label></a> 
       <a href="#"><input type="radio" id="radio6" name="Location" value="Aussie"/><label for="radio6">Aussie</label></a> 
       <a href="#"><input type="radio" id="radio7" name="Location" value="Disneyland"/><label for="radio7">Disneyland</label></a> 
       <a href="#"><input type="radio" id="radio8" name="Location" value="Someplace"/><label for="radio8">Someplace</label></a> 
       <a href="#"><input type="radio" id="radio9" name="Location" value="TheOcean"/><label for="radio9">The Ocean</label></a> 
     </li></ul> 
    </li> 
</ul> 
etc..... 

和我的觀點

arguments = {} 
if request.method == 'GET': 
    sortlocation = request.POST.getlist('Location') 
else: 
    pass 

if sortlocation == []: 
    sortlocation = "World Wide" 
else: 
    sortlocation = sortlocation[0]    
    pass 

if sortlocation is not "World Wide": 
    arguments['Location'] = sortlocation 
else: 
    arguments['Location__isnull'] = False 

回答

0

的示例代碼段,您需要一種方法來存儲狀態。

最簡單的方法是存儲在session信息:像一本字典

sort = request.session.get('sort', None) 
+0

訪問它

request.session['sort'] = 'my_sort_value' 

在任何其他視圖檢索它,雖然讀書很多教程,你總是這樣小部件,即使重新閱讀。這是我錯過的其中一件事。乾杯 – 2011-12-15 04:23:25