Django Admin Export to Excel, CSV, and Others

Export data in django admin into excel spreadsheet, csv and other format using django-import-export library. Official docs here.

Step 1: Preparation, Create Django Project, Initial Migration
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django in virtualenv: pip install django==3.0 django-import-export
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python migrate

Step 2: Create Django Apps
Create apps: python startapp myapp
Add myapp to INSTALLED_APPS in myproject/

Step 3: Create Model in myapp/

Step 4: Register Model in myapp/ and Add ExportActionMixin

Step 5: Makemigrations and Migrate
Make migrations: python makemigrations
Migrate: python migrate

Step 6: Create Superuser
Create superuser: python createsuperuser
Type username, email password and retype password

Step 7: Run Server and Testing
Run Server: python runserver

Add some data, select data, choose format and go (export).



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