Created
July 21, 2022 19:17
-
-
Save vb64/f80d655d04ca1d197517b082bdfbae8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.admin.views.main import ChangeList | |
| ... | |
| def csv_download(self, request): | |
| """View for data download taking into account custom filters and sortings.""" | |
| clist = ChangeList( | |
| request, | |
| self.model, | |
| self.list_display, | |
| self.list_display_links, | |
| self.list_filter, | |
| self.date_hierarchy, | |
| self.search_fields, | |
| self.list_select_related, | |
| self.list_per_page, | |
| self.list_max_show_all, | |
| self.list_editable, | |
| self, | |
| self.sortable_by | |
| ) | |
| return HttpResponse( | |
| queryset2csv(clist.get_queryset(request)), | |
| headers={ | |
| 'Content-Type': 'text/csv', | |
| 'Content-Disposition': 'attachment; filename="data.csv"', | |
| } | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment