O'Reilly logo

Web Development with Django Cookbook - Second Edition by Aidas Bendoraitis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating admin actions

The Django administration system provides actions that we can execute for selected items in the list. There is one action given by default and it is used to delete selected instances. In this recipe, we will create an additional action for the list of the Product model that allows the administrators to export selected products to Excel spreadsheets.

Getting ready

We will start with the products app that we created in the previous recipe.

Make sure that you have the xlwt module installed in your virtual environment to create an Excel spreadsheet:

(myproject_env)$ pip install xlwt

How to do it...

Admin actions are functions that take three arguments: the current ModelAdmin value, the current HttpRequest value, and the QuerySet

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required