我的目标是在ListView中过滤对象。在模板中,我想要一个表单,从中过滤对象。所以我的形式:
class ProductFilterForm(forms.Form):
CHOICES = ((x, x) for x in range(1, 10))
width = forms.ChoiceField(choices=CHOICES)
的观点:
class ProductListView(ListView, FormView):
model = Product
paginate_by = 16
template_name = 'product_list.html'
form_class = ProductFilterForm
def get_context_data(self, **kwargs):
context = super(ProductListView, self).get_context_data(**kwargs)
context['form'] = self.form_class
return context
现在在模板中形成渲染,仅此而已。如何使其过滤对象?