How to reset Django admin action page after returning a FileResponse

I have a Django Admin action that creates and downloads a file in response to a data export request from the user. The file download works fine, but the admin page is left in the same state as when the user first initiated the request, with the row that's being exported still ticked, and the export option still visible in the Admin action dropdown.

How to I return a Django FileResponse, but also return a response that will reset the page?

Can I return the FileResponse as part of a HttpResponseRedirect(request.get_full_path()) or something??

@admin.action(description="Export data for this edition")
def export_edition_action(self, request, queryset):
    buffer = io.BytesIO()
    buffer.write(export_edition(queryset[0]))
    buffer.seek(0)
    response = FileResponse(buffer, as_attachment=True, filename=f'export.json')
    return response
Вернуться на верх