Skip to content

Instantly share code, notes, and snippets.

@gilsondev
Last active August 29, 2015 14:06
Show Gist options
  • Save gilsondev/31b5983e70d720f9760d to your computer and use it in GitHub Desktop.
Save gilsondev/31b5983e70d720f9760d to your computer and use it in GitHub Desktop.
Organizing queryset with alphabetical groups. The glossary style
import string
glossary = []
object_list = Model.objects.all()
for letter in string.ascii_uppercase:
entries = filter(lambda c: letter == c.word[0], object_list)
letter_list = {'letter': letter, 'entries': entries}
glossary.append(letter_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment