Created
July 12, 2015 22:55
-
-
Save josephmosby/2de6cc44d30147ee5c89 to your computer and use it in GitHub Desktop.
kinds of sorting for exact matches
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
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