2020-11-24 12:44:07 +00:00
|
|
|
import csv
|
|
|
|
|
2020-09-21 12:27:16 +00:00
|
|
|
from django.contrib import admin
|
2020-11-24 12:44:07 +00:00
|
|
|
from django.http import HttpResponse
|
2020-09-21 12:27:16 +00:00
|
|
|
|
2021-07-08 06:00:28 +00:00
|
|
|
from .models import Account, Project, HonoraryCertificate, Library, IFG, Travel,\
|
2021-01-04 09:58:47 +00:00
|
|
|
Email, BusinessCard, List, Literature
|
2020-10-06 12:55:46 +00:00
|
|
|
|
2020-11-24 12:44:07 +00:00
|
|
|
|
|
|
|
def export_as_csv(self, request, queryset):
|
|
|
|
|
|
|
|
meta = self.model._meta
|
|
|
|
field_names = [field.name for field in meta.fields]
|
|
|
|
|
|
|
|
response = HttpResponse(content_type='text/csv')
|
|
|
|
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
|
|
|
|
writer = csv.writer(response)
|
|
|
|
|
|
|
|
writer.writerow(field_names)
|
|
|
|
for obj in queryset:
|
|
|
|
row = writer.writerow([getattr(obj, field) for field in field_names])
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
export_as_csv.short_description = "Export Selected"
|
|
|
|
|
|
|
|
admin.site.add_action(export_as_csv)
|
|
|
|
|
2020-10-06 11:17:28 +00:00
|
|
|
@admin.register(Project)
|
|
|
|
class ProjectAdmin(admin.ModelAdmin):
|
2020-11-19 13:41:31 +00:00
|
|
|
save_as = True
|
2021-10-04 13:45:51 +00:00
|
|
|
readonly_fields = ('pid','finance_id','project_of_year')
|
2020-11-24 12:44:07 +00:00
|
|
|
# action = ['export_as_csv']
|
|
|
|
|
|
|
|
|
2020-10-06 11:17:28 +00:00
|
|
|
|
2020-10-06 12:55:46 +00:00
|
|
|
admin.site.register([
|
2021-07-08 06:00:28 +00:00
|
|
|
Account,
|
2020-10-06 12:55:46 +00:00
|
|
|
HonoraryCertificate,
|
2020-09-30 12:17:38 +00:00
|
|
|
Library,
|
|
|
|
IFG,
|
2020-10-26 10:38:56 +00:00
|
|
|
Travel,
|
2020-10-27 10:00:58 +00:00
|
|
|
Email,
|
|
|
|
BusinessCard,
|
2021-01-04 09:58:47 +00:00
|
|
|
List,
|
|
|
|
Literature,
|
2020-09-30 12:17:38 +00:00
|
|
|
])
|