Skip to content

Instantly share code, notes, and snippets.

@bennylope
Created November 16, 2012 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennylope/4088760 to your computer and use it in GitHub Desktop.
Save bennylope/4088760 to your computer and use it in GitHub Desktop.
Simplified filtering without validation
class MyListView(ListView):
def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
search_query = request.GET.get('search_query')
if search_query:
self.object_list = self.object_list.filter(name=search_query)
context = self.get_context_data(object_list=self.object_list)
return self.render_to_response(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment