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. Resource by zvoase 3 years, 8 months ago
  2. EasyFeed class by limodou 5 years, 2 months ago
  3. {% exec %} template tag by aquila 5 years, 1 month ago
  4. render_with decorator by tobias 3 years, 8 months ago
  5. Username form field by sma 3 years, 6 months ago

Comments

showell (on July 6, 2009):

See 1614 for an extension of this.

#

(Forgotten your password?)