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
- Resource by zvoase 3 years, 4 months ago
- EasyFeed class by limodou 4 years, 11 months ago
- {% exec %} template tag by aquila 4 years, 10 months ago
- render_with decorator by tobias 3 years, 5 months ago
- Username form field by sma 3 years, 2 months ago
Comments
See 1614 for an extension of this.
#