2017-07-12 71 views
0

想知道Sessions是否可以用來在我的Django應用上創建兩個產品的快速比較視圖。我列出待售商品並希望用戶能夠「喜歡」多個商品,然後有新的視圖來比較所選產品。有什麼想法嗎?Django的最愛/比較功能

謝謝

回答

1

當然,只是將列表產品分配給會話變量。

然後分配的產品列表中的模板,這可能看起來類似的東西:

<table> 
<tr> 
    <td></td> 
    {% for product in products %} 
    <th>{{ product.title }}</th> 
    {% endfor %} 
</tr> 
<tr> 
    <th>Feature 1</th> 
    {% for product in products %} 
    <td>{{ product.feature1 }}</td> 
    {% endfor %} 
</tr> 
<tr> 
    <th>Feature 2</th> 
    {% for product in products %} 
    <td>{{ product.feature2 }}</td> 
    {% endfor %} 
</tr> 
</table> 
+0

謝謝你看起來不錯,你有如何CBV會看一個例子嗎? – Jack