Django Admin Custom Action

Default action and additional custom action

By default, Django admin provide delete model in action. We can add custom action.

Here some quick steps to add custom action.

Step 1: Preparation
a. Create virtualenv and start it.

b. Install Django

c. Create Django Project

d. Goto Project Folder and Create Django Application

e. Register Django App to Django Project
add ‘myapp’ in INSTALLED_APPS in myproject/settings.py

f. Initial Migrate

g. Create superuser

type username, email, password and retype password.

Step 2: Create Book Model

a. Create Book Model
add book model in myapp/models.py

b. Register model and add custom action
register book model in myapp/admin.py

action above will change selected book to ‘Out of Stock’.

c. Make migration and migrate

Step 3: Start Apps

open http://127.0.0.1:8000/admin open Book menu and add some book data and do some test with new custom action.

--

--

Software Engineer, Indonesia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store