1#
2# SPDX-License-Identifier: GPL-2.0-only
3#
4
5from django import template
6
7register = template.Library()
8
9def field_values(iterable, field):
10    """
11    Convert an iterable of models into a list of strings, one for each model,
12    where the string for each model is the value of the field "field".
13    """
14    objects = []
15
16    if field:
17        for item in iterable:
18            objects.append(getattr(item, field))
19
20    return objects
21
22register.filter('field_values', field_values)