我无法在Django 2.2.5中运行导入导出功能

时间:2019-10-17 12:52:24

标签: django python-3.x django-import-export

我要在Django管理面板数据导入和导出中导入导出选项

https://django-import-export.readthedocs.io/en/stable/getting_started.html

另外,请尝试以下示例

https://simpleisbetterthancomplex.com/packages/2016/08/11/django-import-export.html

python 3.7
django 2.2.5
django-import-export 1.2.0
  

settings.py

IMPORT_EXPORT_USE_TRANSACTIONS = True


models Person
  

resource.py

from import_export import resources
from .models import Person

class PersonResource(resources.ModelResource):
    class Meta:
        model = Person
  

admin.py

from import_export.admin import ImportExportModelAdmin
from django.contrib import admin
from import_export import resources

from .models import Person, Pravacy_check

@admin.register(Person)
class PersonAdmin(ImportExportModelAdmin):
    pass
# Register your models here.

class PersonResource(resources.ModelResource):

    class Meta:
        model = Person

class PersonAdmin(ImportExportModelAdmin):
    resource_class = PersonResource



admin.site.register(PersonAdmin)

所有应用模块的数据导入和导出均需要完善。

1 个答案:

答案 0 :(得分:1)

尝试此代码

from django.contrib import admin
from .models import Person    # 

from import_export import resources

from import_export.admin import ImportExportModelAdmin

class PersonAdmin(ImportExportModelAdmin):   # FOR ADMIN IMPORT EXPORT ONLY 
    pass


admin.site.register(Person, PersonAdmin)   #  FOR ADMIN IMPORT EXPORT ONLY 

Settings.py

 INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'import_export',
        'app',


    ]