sortby template tag

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

  1. improved sortby template tag by gmandx 3 years, 10 months ago
  2. EasyFeed class by limodou 6 years, 2 months ago
  3. Showell markup--DRY up your templates by showell 3 years, 5 months ago
  4. Append paramaters to a GET querystring (template tag) by gregb 3 years, 10 months ago
  5. Imagefield with variations by fivethreeo 4 years, 9 months ago

Comments

showell (on July 6, 2009):

See 1614 for an extension of this.

#

(Forgotten your password?)