mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 20:02:36 +02:00
wip: use model specific filename in admin CSV export
This commit is contained in:
parent
17b67cc5de
commit
9848abb3b1
1 changed files with 4 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import csv
|
import csv
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.contrib.auth.admin import UserAdmin as UserAdminBase
|
from django.contrib.auth.admin import UserAdmin as UserAdminBase
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -14,9 +15,11 @@ class CSVExportMixin:
|
||||||
|
|
||||||
@admin.action(description=_("CSV Export"))
|
@admin.action(description=_("CSV Export"))
|
||||||
def as_csv(self, request, queryset):
|
def as_csv(self, request, queryset):
|
||||||
|
modelname = queryset.model.__name__.lower()
|
||||||
|
filename = f"umap_{modelname}_{datetime.now().isoformat()}.csv"
|
||||||
response = HttpResponse(
|
response = HttpResponse(
|
||||||
content_type="text/csv",
|
content_type="text/csv",
|
||||||
headers={"Content-Disposition": 'attachment; filename="export.csv"'},
|
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
|
||||||
)
|
)
|
||||||
|
|
||||||
writer = csv.writer(response)
|
writer = csv.writer(response)
|
||||||
|
|
Loading…
Reference in a new issue