{"id":88804,"date":"2020-05-03T15:52:41","date_gmt":"2020-05-03T07:52:41","guid":{"rendered":"http:\/\/4563.org\/?p=88804"},"modified":"2020-05-03T15:52:41","modified_gmt":"2020-05-03T07:52:41","slug":"%e8%af%b7%e9%97%ae%e6%9c%89%e7%86%9f%e6%82%89-django-import-export-%e7%9a%84%e6%9c%8b%e5%8f%8b%e5%90%97%ef%bc%8c%e6%b1%82%e8%a7%a3%e7%ad%94%e4%b8%80%e4%b8%aa%e9%97%ae%e9%a2%98%e3%80%82","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=88804","title":{"rendered":"\u8bf7\u95ee\u6709\u719f\u6089 django-import-export \u7684\u670b\u53cb\u5417\uff0c\u6c42\u89e3\u7b54\u4e00\u4e2a\u95ee\u9898\u3002"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u95ee\u6709\u719f\u6089 django-import-export \u7684\u670b\u53cb\u5417\uff0c\u6c42\u89e3\u7b54\u4e00\u4e2a\u95ee\u9898\u3002               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ribuug <\/span>  <span><i><\/i> 15<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u4e00\u4e2a UUID \u7684 \u503c\uff0c\u5bfc\u5165\u591a\u884c\u65f6\u51fa\u9519 \u5c31\u662f\u6211\u5bfc\u5165\u5355\u884c\u7684 xls\uff0c\u6ca1\u95ee\u9898\uff0c\u56e0\u4e3a\u6211\u53ef\u4ee5\u5728 models.py \u91cc\u9762\u6307\u5b9a default=gender_topic_sn()<\/p>\n<p>\u4f46\u662f\u591a\u884c\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a sn \u4ed6\u4e0d\u4f1a\u81ea\u52a8\u751f\u6210\u3002\u56e0\u4e3a\u6211 xls \u91cc\u9762\u5bf9\u5e94\u7684\u662f sn \u7a7a\u7684\u3002\u7136\u540e\u5bfc\u5165\u754c\u9762\u5c31\u51fa\u9519\uff1a <code> \u884c\u53f7: 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: topic_topic.topic_sn <\/code><\/p>\n<p>\u6211\u60f3\u662f\u4e0d\u662f\u8981\u5728\u5bfc\u5165 xls \u7684\u65f6\u5019\uff0c\u6bcf\u884c\u7684\u5728 topic_sn \u8fd9\u4e2a\u503c\uff0c\u8fd0\u884c gender_topic_sn()\uff0c\u751f\u6210\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684 sn \u503c\uff0c\u7ed9\u5230\u5bfc\u5165\u7a0b\u5e8f\uff0c\u4e0e xls \u91cc\u7684\u6570\u636e\u5408\u5728\u4e00\u8d77\u63d2\u5165\u3002\u8fd9\u4e2a\u662f\u4e0d\u662f\u53eb\u5916\u952e\u3002\u3002<\/p>\n<p> <code> def gender_topic_sn(): topic_sn = str(uuid4()).split(\"-\")[0] return topic_sn <\/code> <\/p>\n<p>\u4f46\u662f\u4e0d\u77e5\u9053\u600e\u4e48\u5199<\/p>\n<p>\u6c42\u89e3\u7b54\uff0c\u6298\u817e\u4e86 2 \u4e2a\u661f\u671f\u4e86\uff0chttps:\/\/readthedocs.org\/projects\/django-import-export\/downloads\/pdf\/latest\/ \u770b\u4e86\uff0c\u770b\u4e0d\u61c2\u3002\u5c0f\u767d\u6765\u7684\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1312095\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : banxi1988 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u53ef\u4ee5\u5728 before_import_row() \u65f6\u81ea\u52a8\u751f\u6210\u8fd9\u4e2a topic_sn.<br \/>\u8003\u8651\u5230\u4f60\u662f\u65b0\u624b,\u4f60\u53ef\u4ee5\u52a0\u6211\u5fae\u4fe1\u4ea4\u6d41. \u4e5f\u53ef\u4ee5\u901a\u8fc7 &#8220;\u4ee3\u7801\u4f1a\u8bf4\u8bdd&#8221; \u8fd9\u4e2a\u516c\u4f17\u53f7,\u79c1\u4fe1\u6211                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312096\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lyhapple <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             default=gender_topic_sn() ==&gt; default=gender_topic_sn                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312097\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lyhapple <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u56e0\u4e3a model field \u91cc\u7684 default \u53c2\u6570\u503c\u6307\u5411\u51fd\u6570\u91cc, \u4e0d\u80fd\u52a0\u62ec\u53f7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u95ee\u6709\u719f\u6089 django-impo&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/88804"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88804"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/88804\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88804"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}