0

我正在尝试创建一个搜索表单,但它不起作用。这是我的代码:

class LocationSearchMixin(object):
    def get_queryset(self):
        q = self.request.GET.get('q')
        if q is None:
            return queryset


class StoreListView(LocationSearchMixin, ListView):
    model = Store


<form action="" method="GET">
    <input type="text" name="q" />
    <button type="submit">search</button>
</form>
4

1 回答 1

0

您必须在 LocationSearchMixin 中添加一些内容:

class LocationSearchMixin(object):
    def get_queryset(self):
        queryset = super(LocationSearchMixin, self).get_queryset()
        q = self.request.GET.get('q')
        if q is None:
            return queryset
        return queryset.filter(location__istartswith=q)
于 2013-02-12T03:03:12.887 回答