How to add actions to Python django admin page

1k Views Asked by At

I have a django project in which the the form records the name and the email addresses of the users and I was able to put that data using forms.py and models.py. What I want to do nextis to create an action through which I can download that in csv file.

enter image description here

My admin page looks like this now and I want to add action right above.

1

There are 1 best solutions below

0
On

in order to add an action to a model in the admin page you have to create a new class like this and register it with your model:

admin.py

from youSite.views import downloadCSV
from yourSite.models import Info

class infoAdmin(admin.ModelAdmin):
    actions =[downloadCSV]


admin.site.register(infoObject, infoAdmin)

You have to create the function in your views and import it into the admin page. It create a new action in that model. Hope it helps