Skip to content

Instantly share code, notes, and snippets.

View ochui's full-sized avatar
🌏
Working from home and farm

Ochui, Princewill Patrick ochui

🌏
Working from home and farm
View GitHub Profile
@jeremyjbowers
jeremyjbowers / actions.py
Created November 24, 2015 21:47
Export to CSV for Django admin
import csv
from django.http import HttpResponse
def export_as_csv_action(description="Export selected objects as CSV file", fields=None, exclude=None, header=True):
"""
This function returns an export csv action
'fields' and 'exclude' work like in django ModelForm
'header' is whether or not to output the column names as the first row
"""
def export_as_csv(modeladmin, request, queryset):