2013-02-12 3 views
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> 

답변

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)