Skip to content

Instantly share code, notes, and snippets.

@josephmosby
Created July 12, 2015 22:55
Show Gist options
  • Save josephmosby/2de6cc44d30147ee5c89 to your computer and use it in GitHub Desktop.
Save josephmosby/2de6cc44d30147ee5c89 to your computer and use it in GitHub Desktop.
kinds of sorting for exact matches
sorted(queryset.filter(id__in=collection_list), key=lambda s: s.headline.lower().startswith(kwargs['query']))
# this way will do a sort of the queryset based on whether it starts with the search term
sorted(self.model.objects.filter(id__in=collection_list), key=lambda s: kwargs['query'] in s.headline.lower(), reverse=True)
# this way will do a sort of the queryset based on whether it's an exact match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment