Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增xadmin导入导出插件,集成django-import-export,支持多种格式数据导入导出 #433

Merged
merged 3 commits into from
Sep 5, 2017

Conversation

zcyuefan
Copy link
Contributor

@zcyuefan zcyuefan commented Sep 4, 2017

你好:
xadmin有很多实用功能,不过目前只有导出没有导入,很多同学也遇到了和我一样的问题。所以我结合了django-import-export做出了导入功能,顺便做了对应的导出功能(与原有导出不冲突)。
ps:第一次向这么高大上的项目提交代码,我自己也不是纯粹的开发人员,希望管理员能多多指导,万分感谢。
导入导出插件使用方法示例:

#Use:
#+++ settings.py +++
INSTALLED_APPS = (
    ...
    'import_export',
)

#+++ models.py +++
from django.db import models

class Foo(models.Model):
    name = models.CharField(max_length=64)
    description = models.TextField()

#+++ adminx.py +++
import xadmin
from import_export import resources
from .models import Foo

class FooResource(resources.ModelResource):
“”“
设置导入及导出的Resource类
”“”
    class Meta:
        model = Foo
        # fields = ('name', 'description',)
        # exclude = ()


@xadmin.sites.register(Foo)
class FooAdmin(object):
    # 声明import_export_args参数导入和导出的Resource类后,list页面便有导入和导出按钮
    import_export_args = {'import_resource_class': FooResource, 'export_resource_class': FooResource}

@sshwsfc sshwsfc merged commit 07a4c70 into sshwsfc:master Sep 5, 2017
@zhuangdx
Copy link

zhuangdx commented Sep 20, 2017

数据导出,中英文交互,只有“导出全部数据”’是中文

导出 Host

格式:
Export current page data. Export selected data. 导出全部数据 Export header only.

没有截图,希望明白意思

@zcyuefan
Copy link
Contributor Author

@Dorxa ,之前提交代码出现了疏忽,那几个词本地化失败,查看这里已修复。

@soulrenger
Copy link

soulrenger commented Mar 19, 2018

在python3.6.3(使用的是miniconda环境),django 1.11.4环境下,导出页面还是部分有英文,而且无法导出当前的列表页,导出为空,导出文件的名称也是乱码状态

显示截图:

snipaste_2018-03-19_12-09-06

文件乱码:

文件名乱码:

_xe6_xb5_x8b_xe8_xaf_x95 

在python3环境下
以类似的utf8字符串开头显示乱码文件,确定已经使用了最新版本的xadmin插件,也对比过本地化文件

系统环境

软件包 版本号
django 1.11.4
import_export 1.0.0
xadmin 0.6.0
python 3.6.3

更新下:
导出为空是因为我在resource文件处设置了

fields = "__all__"    # 此处编码导致了导出为空

现可成功导出csv和xls格式,excel2007格式,yml格式分别会报错
excel 2007格式 报错:

TypeError: cell() missing 1 required positional argument: 'column'

yml格式报错为:

RepresenterError: cannot represent an object: 495.73

似乎是无法正确的识别出小数点的数字

@soulrenger
Copy link

更新:
导出xlsx错误的问题是由于openpyxl最新版本导致的,需要修改tablib源码,或者降级openpyxl版本号,
相关讨论在这里:https://github.com/kennethreitz/tablib/issues/324
修复tablib的代码在这里:Dallinger/tablib@13747e9

@water4168
Copy link

@zcyuefan 导入xls文件,只有最后一条数据是导入成功。请教下,代码那个部分是处理存入数据库的?

@zcyuefan
Copy link
Contributor Author

zcyuefan commented Jul 9, 2019

@walterliang 处理存入数据都是django-import-export库 resources.import_data做的,你可以检查下你的excel数据,也可以在这个方法上打断点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants