🎇

【手順書】django-import-export

2021/10/08に公開約700字

必要なパッケージ

https://django-import-export.readthedocs.io/en/stable/
https://github.com/django-import-export/django-import-export
pip install django-import-export

settings.pyの設定

# settings.py
INSTALLED_APPS = [
    ....
    'import_export',
    ....
]

admin.pyの設定

from django.contrib import admin
from import_export import resources
from import_export.admin import ImportExportModelAdmin
from import_export.fields import Field
from .models import Employee


class EmployeeResource(resources.ModelResource):
    id = Field(attribute='id', column_name='id')
    name = Field(attribute='name', column_name='name')

    class Meta:
        model = Employee
        skip_unchanged = True
        use_bulk = True

Discussion

ログインするとコメントできます