Skip to content

Instantly share code, notes, and snippets.

@Ogreman
Created November 5, 2013 15:50
Show Gist options
  • Select an option

  • Save Ogreman/7321132 to your computer and use it in GitHub Desktop.

Select an option

Save Ogreman/7321132 to your computer and use it in GitHub Desktop.
class TermSearchMixin(object):
term = "title"
def get_queryset(self):
queryset = super(TermSearchMixin, self).get_queryset()
q = self.request.GET.get("q")
if q:
return queryset.filter(
**{
self.term + "__icontains": q,
}
)
return queryset
def get_context_data(self, **kwargs):
context = super(
TermSearchMixin,
self
).get_context_data(**kwargs)
if hasattr(self.request, 'path'):
context['simple_path'] = self.request.path
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment