These are achieved with a library called django-import-export
.
This is a summary article on how to use django-import-export (introduction method).
This time, I created an account with the following privileges.
--admin: full privileges --guest: View permission only
←このボタンが追加される
←このボタンが追加される
The format is as follows. Abundant.
The format is as follows. Even more abundant than imports.
django-import-export https://django-import-export.readthedocs.io/en/latest/
pip install django-import-export
setting.py
#Installed app
INSTALLED_APPS = (
...
'import_export',
)
#Set that the import function on the management site requires permission
IMPORT_EXPORT_IMPORT_PERMISSION_CODE = 'change'
python manage.py collectstatic
Assuming there is a table named Book
in model.py
admin.py
from django.contrib import admin
from import_export import resources
from import_export.admin import ImportExportModelAdmin
from .models import *
#resource
class BookResource(resources.ModelResource):
class Meta:
model = Book
#management
class BookAdmin(ImportExportModelAdmin):
resource_class = BookResource
#Registration
admin.site.register(Book, BookAdmin)
Simple and highly functional! Great. This time, all files were exported, but it seems that you can also filter. I want to challenge.
Recommended Posts