Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
Diskominfo-D'Blood
Mantan Aab-D Blood
Commits
d7325369
Verified
Commit
d7325369
authored
Jun 02, 2020
by
Giovan Isa Musthofa
Browse files
[GREEN] Add download_acara_donor action to JadwalDonorAdmin
parent
a57489be
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/donor/admin.py
View file @
d7325369
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
workbook
.
close
()
return
response
download_jadwaldonor
.
short_description
=
'Download Jadwal Donor as Excel Workbook'
@
admin
.
register
(
JadwalDonor
)
class
JadwalDonorAdmin
(
admin
.
ModelAdmin
):
list_filter
=
(
'kecamatan'
,
'time_start'
,
'category'
)
actions
=
[
download_jadwaldonor
]
@
admin
.
register
(
DaftarDonor
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment