Fakultas Ilmu Komputer UI

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

[GREEN] Add download_acara_donor action to JadwalDonorAdmin

parent a57489be
from django.contrib import admin
from django.http import HttpResponse
from donor.models import JadwalDonor, DaftarDonor
def download_jadwaldonor(modeladmin, request, queryset):
import pandas as pd
from django_pandas.io import read_frame
response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = f'attachment; filename={modeladmin.model._meta}.xlsx'
df = read_frame(queryset)
df['time_start'] = df['time_start'].dt.tz_localize(None)
df['time_end'] = df['time_end'].dt.tz_localize(None)
writer = pd.ExcelWriter(response, engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
workbook = writer.book
return response
download_jadwaldonor.short_description = 'Download Jadwal Donor as Excel Workbook'
class JadwalDonorAdmin(admin.ModelAdmin):
list_filter = ('kecamatan', 'time_start', 'category')
actions = [download_jadwaldonor]
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