diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/templatetags/field_values_filter.py')
-rw-r--r-- | bitbake/lib/toaster/toastergui/templatetags/field_values_filter.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/templatetags/field_values_filter.py b/bitbake/lib/toaster/toastergui/templatetags/field_values_filter.py new file mode 100644 index 0000000000..5a73af797c --- /dev/null +++ b/bitbake/lib/toaster/toastergui/templatetags/field_values_filter.py | |||
@@ -0,0 +1,18 @@ | |||
1 | from django import template | ||
2 | |||
3 | register = template.Library() | ||
4 | |||
5 | def field_values(iterable, field): | ||
6 | """ | ||
7 | Convert an iterable of models into a list of strings, one for each model, | ||
8 | where the string for each model is the value of the field "field". | ||
9 | """ | ||
10 | objects = [] | ||
11 | |||
12 | if field: | ||
13 | for item in iterable: | ||
14 | objects.append(getattr(item, field)) | ||
15 | |||
16 | return objects | ||
17 | |||
18 | register.filter('field_values', field_values) \ No newline at end of file | ||