Skip to content

Instantly share code, notes, and snippets.

@anddam
Last active February 12, 2017 10:27
Show Gist options
  • Select an option

  • Save anddam/0404302481829cf822f55da2ac65f22a to your computer and use it in GitHub Desktop.

Select an option

Save anddam/0404302481829cf822f55da2ac65f22a to your computer and use it in GitHub Desktop.
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