Return a comma-separated list of models, optionaly with a link.

def csv_list(models, attr, link=False, separator=", "):
    """Return a comma-separated list of models, optionaly with a link."""
    values = []
    for model in models:
        value = getattr(model, attr)
        if link and hasattr(model, "get_admin_url") and callable(model.get_admin_url):
            value = get_admin_html_link(model, label=value)
        values.append(value)
    return separator.join(values)