[PYTHON] Excel, csv import, export with Django

How to import or export Djang model from excel, csv

Use the django-import-export plugin

You will be able to use import export quickly. django-import-export

Installation method https://kurozumi.github.io/django-import-export/installation.html

Use ImportExportActionModelAdmin instead of ModelAdmin in admin.py in each app folder

from import_export.admin import ImportExportActionModelAdmin
from sampleapp.models import SampleData

class SampleDataAdmin(ImportExportActionModelAdmin):
    names = [f.name for f in SampleData._meta.get_fields() if not isinstance(f, models.ManyToOneRel)]
    list_display = names
    list_filter = ['sample_row1', 'sample_row2', 'sample_row3',]

With this alone, you can use json and yaml in addition to csv and excel. Import is performed by selecting data from the upper right of the admin list screen, and exporting is performed by selecting data from the operation.

Implemented by scratch

It's easy to use the django-import-export plugin, but if you really don't want to use it, the implementation method is described in the link below. I think this site is also good for studying Django admin. https://books.agiliq.com/projects/django-admin-cookbook/en/latest/export.html https://books.agiliq.com/projects/django-admin-cookbook/en/latest/import.html

Recommended Posts

Excel, csv import, export with Django
[Django] Import and export DB tables in Excel or CSV format
Handle csv files with Django (django-import-export)
Handle Excel CSV files with Python
Export & Import Trained Models with PyBrain
Internationalization with django
CRUD with Django
Excel with Python
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Development digest with Django
Add CSV export function to management screen with django-import-export
Output PDF with Django
Markdown output with Django
Use Gentelella with django
Twitter OAuth with Django
Getting Started with Django 1
Handle Excel with python
How to export / import Zope zope object installed with Plone-4.1.5-UnifiedInstaller-20120604.tgz
Send email with Django
File upload with django
unable to import django
Use LESS with Django
Pooling mechanize with Django
Csv tinkering with python
Import tsv with Python
Use MySQL with Django
Read excel with openpyxl
Start today with Django
Operate Excel with Python (1)
Getting Started with Django 2
Operate Excel with Python (2)
Operate Excel with Python openpyxl
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Read csv with python pandas
Graph Excel data with matplotlib (1)
Minimal website environment with django
Create an API with Django
Let's run Excel with Python
Do Django with CodeStar (Python3.8, Django2.1.15)
Python3 + Django ~ Mac ~ with Apache
Getting Started with Python Django (1)
Get started with Django! ~ Tutorial ④ ~
Getting Started with Python Django (4)
Web application creation with Django
Getting Started with Python Django (3)
Graph Excel data with matplotlib (2)
Combine FastAPI with Django ORM
Get started with Django! ~ Tutorial ⑥ ~
Save tweet data with Django
AWS Lambda with PyTorch [Lambda import]
Do AES encryption with DJango
Write to csv with Python
Getting Started with Python Django (6)
Combine two images with Django
Getting Started with Django with PyCharm
Real-time web with Django Channels
Double submit suppression with Django
Django REST framework with Vue.js
Server management with Jupyter (1) import