1 2 3 4 5 6 7 8 9 | from django.template import Library
register = Library()
@register.filter
def sortby (sequence, attribute):
# variation on dictsort using attribute access
lst = list(sequence)
lst.sort(key=lambda obj: getattr(obj,attribute))
return lst
|
More like this
- improved sortby template tag by gmandx 3 years, 11 months ago
- EasyFeed class by limodou 6 years, 3 months ago
- Showell markup--DRY up your templates by showell 3 years, 6 months ago
- Append paramaters to a GET querystring (template tag) by gregb 3 years, 11 months ago
- Imagefield with variations by fivethreeo 4 years, 10 months ago
Comments
See 1614 for an extension of this.
#