def export_as_csv_action(description="<STR_LIT>", fields=None, header=True):
<EOL>def export_as_csv(modeladmin, request, queryset):  <EOL><INDENT>"""<STR_LIT>"""<EOL>opts = modeladmin.model._meta<EOL>if not fields:<EOL><INDENT>field_names = [field.name for field in opts.fields]<EOL><DEDENT>else:<EOL><INDENT>field_names = fields<EOL><DEDENT>response = HttpResponse(content_type="<STR_LIT>")<EOL>response["<STR_LIT>"] = "<STR_LIT>".format(<EOL>filename=str(opts).replace("<STR_LIT:.>", "<STR_LIT:_>")<EOL>)<EOL>writer = unicodecsv.writer(response, encoding="<STR_LIT:utf-8>")<EOL>if header:<EOL><INDENT>writer.writerow(field_names)<EOL><DEDENT>for obj in queryset:<EOL><INDENT>row = []<EOL>for field_name in field_names:<EOL><INDENT>field = getattr(obj, field_name)<EOL>if callable(field):<EOL><INDENT>value = field()<EOL><DEDENT>else:<EOL><INDENT>value = field<EOL><DEDENT>if value is None:<EOL><INDENT>row.append("<STR_LIT>")<EOL><DEDENT>elif not value and isinstance(value, string_types):<EOL><INDENT>row.append("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>row.append(value)<EOL><DEDENT><DEDENT>writer.writerow(row)<EOL><DEDENT>return response<EOL><DEDENT>export_as_csv.short_description = description<EOL>return export_as_csv<EOL>
Return an export csv action.

Arguments:
    description (string): action description
    fields ([string]): list of model fields to include
    header (bool): whether or not to output the column names as the first row