Fakultas Ilmu Komputer UI

Verified Commit 4182a238 authored by Giovan Isa Musthofa's avatar Giovan Isa Musthofa
Browse files

[GREEN] Add download_acara_donor action to AcaraDonorAdmin

parent 6f559981
from django.http import HttpResponse
from django.contrib import admin
from acara_donor.models import AcaraDonor
from acara_donor.filters import AcaraDonorFilter
def download_acara_donor(modeladmin, request, queryset):
import xlsxwriter
response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = f'attachment; filename={modeladmin.model._meta}.xlsx'
workbook = xlsxwriter.Workbook(response)
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello world')
workbook.close()
return response
download_acara_donor.short_description = 'Download Acara Donor as Excel Workbook'
@admin.register(AcaraDonor)
class AcaraDonorAdmin(admin.ModelAdmin):
list_filter = ('status', AcaraDonorFilter, 'alamat_lokasi_donor')
......@@ -15,3 +35,4 @@ class AcaraDonorAdmin(admin.ModelAdmin):
'nama_koor',
'email_koor',
'no_telp_koor')
actions = [download_acara_donor]
......@@ -7,3 +7,4 @@ django-anymail==7.0.0
djangorestframework==3.11.0
django-cors-headers==3.2.1
gunicorn==20.0.4
XlsxWriter==1.2.9
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment