Skip to content

Instantly share code, notes, and snippets.

@cavb
Last active July 25, 2016 21:50
Show Gist options
  • Save cavb/677f3f1f9189851209da5797f8e4e38d to your computer and use it in GitHub Desktop.
Save cavb/677f3f1f9189851209da5797f8e4e38d to your computer and use it in GitHub Desktop.
Python: Print only names of an array ordered by name
def print_categories(self):
''' Return categories as text for printing on templates '''
return ''.join(
[x.name +'-' for x in self.category.all().order_by('name')]
)[:-1] # Removes last '-'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment