Created
November 5, 2013 15:50
-
-
Save Ogreman/7321132 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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