Skip to content

Instantly share code, notes, and snippets.

@dlyapun
Created August 4, 2017 10:06
Show Gist options
  • Save dlyapun/67522ce2fa228217b116a001d4033137 to your computer and use it in GitHub Desktop.
Save dlyapun/67522ce2fa228217b116a001d4033137 to your computer and use it in GitHub Desktop.
def get_search_results(self, request, queryset, search_term):
queryset, use_distinct = super(OogleUserAdmin, self).get_search_results(request, queryset, search_term)
if search_term.isdigit():
queryset = self.model.objects.filter(Q(id=search_term) | Q(dentist__dentist_id=search_term) | Q(login_dentist__dentist_id=search_term))
sort_param = request.GET.get('o', '').split('.')
full_sort_param = []
index = 1
for field in self.list_display:
for param in sort_param:
if str(index) in param:
full_sort_param.append(param.replace(str(index), field))
index += 1
queryset = queryset.order_by(*full_sort_param)
return queryset, use_distinct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment