Add make_choices function.
[matthijs/projects/xerxes.git] / tools / misc.py
index ba84f05e87141c0be4a9e2efd14bdf1d906dbc1d..2c785482e5a9e1da735a4d05c3b75ec41b78493b 100644 (file)
@@ -28,3 +28,15 @@ def log_error(func):
             traceback.print_exc()
             raise e
     return show
+
+def make_choices(objects):
+    """
+    Transforms a list (or iteratable) of model objects to a list
+    suitable to be used as a list of choices in form widgets like
+    Select.
+
+    This fullfills a similar (but simpler) function as
+    django.forms.models.ModelChoiceIterator, but that one requires a
+    FormField and is not public.
+    """
+    return [(o.pk, o) for o in objects]