请问有熟悉 django-import-export 的朋友吗,求解答一个问题。 - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ribuug

请问有熟悉 django-import-export 的朋友吗,求解答一个问题。

  •  
  •   ribuug Apr 27, 2020 2362 views
    This topic created in 2221 days ago, the information mentioned may be changed or developed.

    有一个 UUID 的 值,导入多行时出错 就是我导入单行的 xls,没问题,因为我可以在 models.py 里面指定 default=gender_topic_sn()

    但是多行的时候,这个 sn 他不会自动生成。因为我 xls 里面对应的是 sn 空的。然后导入界面就出错: 行号: 2 - UNIQUE constraint failed: topic_topic.topic_sn , , , a, , 22.0, 58.0, , , aaa, , Traceback (most recent call last): File "/home/ubuntu/django/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "/home/ubuntu/django/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute return Database.Cursor.execute(self, query, params) sqlite3.IntegrityError: UNIQUE constraint failed: toic_topic.topic_sn

    我想是不是要在导入 xls 的时候,每行的在 topic_sn 这个值,运行 gender_topic_sn(),生成一个不重复的 sn 值,给到导入程序,与 xls 里的数据合在一起插入。这个是不是叫外键。。

    def gender_topic_sn(): topic_sn = str(uuid4()).split("-")[0] return topic_sn

    但是不知道怎么写

    求解答,折腾了 2 个星期了,https://readthedocs.org/projects/django-import-export/downloads/pdf/latest/ 看了,看不懂。小白来的。

    3 replies    2020-04-27 14:33:51 +08:00
    banxi1988
        1
    banxi1988  
       Apr 27, 2020
    你可以在 before_import_row() 时自动生成这个 topic_sn.
    考虑到你是新手,你可以加我微信交流. 也可以通过 "代码会说话" 这个公众号,私信我
    lyhapple
        2
    lyhapple  
       Apr 27, 2020
    default=gender_topic_sn() ==> default=gender_topic_sn
    lyhapple
        3
    lyhapple  
       Apr 27, 2020
    因为 model field 里的 default 参数值指向函数里, 不能加括号
    About     Help     Advertise     Blog     API     FAQ     Solana     5384 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 72ms UTC 07:14 PVG 15:14 LAX 00:14 JFK 03:14
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86