Django Admin Export to Excel, CSV, and Others

Adi Ramadhan
2 min readNov 22, 2020

--

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 manage.py migrate

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

Step 3: Create Model in myapp/models.py

Step 4: Register Model in myapp/admin.py and Add ExportActionMixin

Step 5: Makemigrations and Migrate
Make migrations: python manage.py makemigrations
Migrate: python manage.py migrate

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

Step 7: Run Server and Testing
Run Server: python manage.py runserver
Access: http://127.0.0.1:8000/admin

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

--

--

Adi Ramadhan
Adi Ramadhan

Responses (3)