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. InlineFormset Template by petry 5 years, 5 months ago
  2. "If in" template tag by andrew 5 years, 12 months ago
  3. partition template filters by SmileyChris 6 years, 7 months ago
  4. django image bundle exaple template by amitu 6 years, 10 months ago
  5. Template Tag Caveat by ericmoritz 5 years, 10 months ago

Comments

(Forgotten your password?)