Django Admin 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.

> virtualenv venv
> venv\Scripts\activate

b. Install Django

(venv)> pip install django

c. Create Django Project

(venv)> django-admin startproject myproject

d. Goto Project Folder and Create Django Application

(venv)> cd myproject
(venv)/ myproject> python startapp myapp

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

f. Initial Migrate

(venv)/ myproject> python migrate

g. Create superuser

(venv)/ myproject> python createsuperuser

type username, email, password and retype password.

Step 2: Create Book Model

a. Create Book Model
add book model in myapp/

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

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

c. Make migration and migrate

(venv)/ myproject> python makemigrations
(venv)/ myproject> python migrate

Step 3: Start Apps

(venv)/ myproject> python runserver

open open Book menu and add some book data and do some test with new custom action.



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