Django 3: Set a Model Import/Export in /admin

DJango Admin template for model State. You will import and export today! 🙌
  • be a little better in Django and dev, man!
  • Create Resources in Django Admin
  • One of the best “Importer” and “Exporter” in Django Admin, congrats!
  • share what you learned with others! That’s the magic! You receive, you give!

First of all: Modules and versions considered in this example

This example consider that you have installed Python, Django, dependencies, migrate models and config admin.

1°: What we will do…

Install package django-import-export

Step 2: Add django-import-export to INSTALLED_APPS

project/settings.py

Step 3: Class Resource to your ModelAdmin

project/app/resources.py
  • Import the modules below:
project/app/resources.py
  • Set field from related Model and class Meta to your set Model and options of resources. You can see all options in readthedocs. Below I set:
project/app/resources.py

Step 4: Set your ModelAdmin

  • Import module ImportExportModelAdmin
  • Import the resource that you create in step 3
  • set the property resource_class to your Resource that you created
  • Don’t forget to register in your Model and ModelAdmin to you see in your /admin
project/app/admin.py

Step 5: Importing datas to database.

http://project_url/admin/locals/state/
http://project_url/admin/locals/state/import/

Export

Finally

Some usefull links

--

--

--

In love with tech, this space is to learn and to share what I know or learned with you! Let’s go!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fenomy Ambassador Program

My first weeks with Linux on desktop

How I made my first website clone & how you can too.

Binary Search

Platformer: Collectible & Status Bar

Coding w/ Python Part 1- How to Start

RIDER SK 1.How to apply the Vlookup function on Excel database?

Gitlab CI/CD for a Dockerized Flask and Next.js Application

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
Marcello Bastos

Marcello Bastos

In love with tech, this space is to learn and to share what I know or learned with you! Let’s go!

More from Medium

mysqlclient with Python 3.10 / Docker

Docker zing a Python Django Web App on Ubuntu

Change rest_framework’s request parameter validation failure response

Python: Audit Logs API Client