Commits

João Pedro Francese  committed f2a2195

Added queryset_str_join().

  • Participants
  • Parent commits 8d28ca6

Comments (0)

Files changed (1)

File inoa/models/utils.py

                 field.verbose_name = overrides[field.name]
         return original_class
     return decorator
+
+def queryset_str_join(queryset, separator, text_if_empty=""):
+    """
+    Joins the queryset's elements into a string, in the same way as str.join(list).
+    If the queryset is empty, returns the text_if_empty arguments (defaults to an empty string).
+    """
+    if queryset:
+        return separator.join(map(lambda s: unicode(s), queryset))
+    else:
+        return text_if_empty