Skip to content
Browse files

Adding min/max filters

  • Loading branch information...
1 parent d88e9d5 commit fda808acc5423817c3f6c562bc259ea632cecd8a @nathanborror committed
Showing with 27 additions and 0 deletions.
  1. +27 −0 basic/tools/templatetags/numtuils.py
View
27 basic/tools/templatetags/numtuils.py
@@ -0,0 +1,27 @@
+from django.template import Library
+
+register = Library()
+
+
+@register.filter
+def min(object_list, field):
+ """
+ Returns the min value given an object_list and a field.
+
+ Example:
+ {{ forecast|min:"high_temp" }}
+ """
+ value_list = [getattr(o, obj, None) for o in object_list]
+ return min(value_list)
+
+
+@register.filter
+def max(object_list, field):
+ """
+ Returns the max value given an object_list and a field.
+
+ Example:
+ {{ forecast|max:"high_temp" }}
+ """
+ value_list = [getattr(o, obj, None) for o in object_list]
+ return max(value_list)

0 comments on commit fda808a

Please sign in to comment.
Something went wrong with that request. Please try again.