0

I am trying to use this snippet for exporting the admin models as a CSV file .
It is working fine in this way:

Added the downloaded snippet as actions.py and write below code in the admin.py of any app

from actions import export_as_csv_action

class YourModelAdmin(admin.ModelAdmin):
    list_display = (...)
    list_filter = [...]
    actions = [export_as_csv_action("CSV Export", fields=['field1', 'field2'])]

The above method is working but in this method we have to add the action to every model separately . There is another way to add the action to all the models in an app by writing the below code in the admin.py of that app.

from django.contrib import admin

admin.site.add_action(export_as_csv_action, "export csv")

From the above code, the action "export csv" is being displayed in the admin page, but when I select it and click GO, then nothing is happening, just page is being redirected to the same page, can you please tell me what I have done wrong?

4

1 回答 1

0

您忘记了“export_as_csv_action()”调用中的括号:

from django.contrib import admin

admin.site.add_action(export_as_csv_action(), "export csv")
于 2012-10-17T18:28:47.807 回答