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.
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