Skip to content

Commit fda808a

Browse files
committed
Adding min/max filters
1 parent d88e9d5 commit fda808a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django.template import Library
2+
3+
register = Library()
4+
5+
6+
@register.filter
7+
def min(object_list, field):
8+
"""
9+
Returns the min value given an object_list and a field.
10+
11+
Example:
12+
{{ forecast|min:"high_temp" }}
13+
"""
14+
value_list = [getattr(o, obj, None) for o in object_list]
15+
return min(value_list)
16+
17+
18+
@register.filter
19+
def max(object_list, field):
20+
"""
21+
Returns the max value given an object_list and a field.
22+
23+
Example:
24+
{{ forecast|max:"high_temp" }}
25+
"""
26+
value_list = [getattr(o, obj, None) for o in object_list]
27+
return max(value_list)

0 commit comments

Comments
 (0)