This function allows to easily filter choices for model fields, without
duplicating descriptions.
FormField and is not public.
"""
return [(o.pk, o) for o in objects]
+
+def filter_choices(choices, filter):
+ """
+ Returns the given choices list with only the choices with the names
+ in filter left. For example, when a model defines
+ A = 'A'
+ B = 'B'
+ FOO_CHOICES = (
+ (A, "Foo A"),
+ (B, "Foo B")
+ )
+
+ you can later define a modelfield using
+
+ foo = ChoiceField(choices=filter_choices(Foo.FOO_CHOICES, [Foo.A]))
+ """
+ return [(name, value) for (name, value) in choices if name in filter]