{"id":89065,"date":"2019-07-31T11:54:20","date_gmt":"2019-07-31T03:54:20","guid":{"rendered":"http:\/\/4563.org\/?p=89065"},"modified":"2019-07-31T11:54:20","modified_gmt":"2019-07-31T03:54:20","slug":"django-%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%ef%bc%8c%e5%a6%82%e4%bd%95%e7%94%a8%e8%87%aa%e5%a2%9e-id-%e4%bd%9c%e4%b8%ba%e5%9b%be%e7%89%87%e7%9a%84%e5%90%8d","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=89065","title":{"rendered":"Django \u56fe\u7247\u4e0a\u4f20\uff0c\u5982\u4f55\u7528\u81ea\u589e id \u4f5c\u4e3a\u56fe\u7247\u7684\u540d"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Django \u56fe\u7247\u4e0a\u4f20\uff0c\u5982\u4f55\u7528\u81ea\u589e id \u4f5c\u4e3a\u56fe\u7247\u7684\u540d               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dolaxi <\/span>  <span><i><\/i> 52<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6211\u672c\u610f\u662f\u60f3\u56fe\u7247\u4e0a\u4f20\u7684\u65f6\u5019\uff0c\u7528\u6570\u636e\u5e93\u81ea\u589e id \u4f5c\u4e3a\u56fe\u7247\u7684\u540d\u79f0<\/p>\n<p>models.py<\/p>\n<p>&#8221;&#8217;<br \/>class Goods(models.Model):<br \/> image = models.ImageField(upload_to=pic_path,verbose_name=&#8217;\u5c01\u9762\u56fe&#8217;)<br \/> create_time = models.DateTimeField(auto_now_add=True,verbose_name=&#8217;\u521b\u5efa\u65f6\u95f4&#8217;)<\/p>\n<p>def pic_path(instance, filename):<br \/> #\u81ea\u5b9a\u4e49\u4fdd\u5b58\u8def\u5f84\u548c\u6587\u4ef6\u540d<\/p>\n<p> # \u6e90\u6587\u4ef6\u540d\u540e\u7f00<br \/> ext = filename.split(&#8216;.&#8217;)[-1]<br \/> # \u6587\u4ef6\u540d<br \/> # new_name = datetime.now().strftime(&#8216;%Y%m\/&#8217;)+shortuuid.uuid()<br \/> # new_name =instance.id #\u65e0\u6548<br \/> new_name =<\/p>\n<p> # \u62fc\u63a5\u6587\u4ef6\u540d\u548c\u540e\u7f00<br \/> path = new_name + &#8216;.&#8217; + ext<br \/> return path<\/p>\n<p>&#8221;&#8217;      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Django \u56fe\u7247\u4e0a\u4f20\uff0c\u5982\u4f55\u7528\u81ea\u589e&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\/89065"}],"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=89065"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/89065\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89065"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}