安装Django-import-export插件
pip install django-import-export
setting.py里面注册
'import_export',
在admin.py里面注册
之前我们在这个里面注册的代码是
class SubjectAdmin(admin.ModelAdmin):
list_display = ['subname']
ordering = (u'id',)
list_filter = ['subname']
list_per_page = 5
admin.site.register(Subject, SubjectAdmin)
现在我们使用的东西不是这了
我们要这样写,继承的东西多了
from apps.wygl.models import TbCommunity
from import_export import resources
from import_export.admin import ImportExportActionModelAdmin
class ProxyResource(resources.ModelResource):
class Meta:
model = TbCommunity
export_order = ('id', 'code', 'name')
class TbCommunityAdmin(ImportExportActionModelAdmin):
list_per_page = 5
resource_class = ProxyResource
admin.site.register(TbCommunity, TbCommunityAdmin)
效果
|