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