Last active
February 12, 2017 10:27
-
-
Save anddam/0404302481829cf822f55da2ac65f22a 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 TestRequestLoginListView(LoginListView): | |
| model = models.TestRequest | |
| paginate_by = 10 | |
| def get_queryset(self): | |
| objects = self.model.objects.all() | |
| filter_argument = self.request.GET.get('filter') | |
| if filter_argument: | |
| conditions = [Q(config__name__icontains=word) for word in filter_argument.split()] | |
| filter_condition = reduce(or_, conditions) | |
| objects = objects.filter(filter_condition) | |
| orderby_argument = self.request.GET.get('orderby') | |
| if orderby_argument: | |
| objects = objects.order_by(orderby_argument) | |
| return objects | |
| def get_context_data(self, **kwargs): | |
| context = super().get_context_data(**kwargs) | |
| context['filter'] = self.request.GET.get('filter', 'give-default-value') | |
| context['orderby'] = self.request.GET.get('orderby', 'give-default-value') | |
| return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment