{"id":89067,"date":"2019-07-31T13:46:26","date_gmt":"2019-07-31T05:46:26","guid":{"rendered":"http:\/\/4563.org\/?p=89067"},"modified":"2019-07-31T13:46:26","modified_gmt":"2019-07-31T05:46:26","slug":"django-%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=89067","title":{"rendered":"Django \u5982\u4f55\u7528\u81ea\u589e id \u4f5c\u4e3a\u56fe\u7247\u7684\u540d"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Django \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> 55<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\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<pre><code>models.py   class Goods(models.Model):     image = models.ImageField(upload_to=pic_path,verbose_name='\u5c01\u9762\u56fe')     create_time = models.DateTimeField(auto_now_add=True,verbose_name='\u521b\u5efa\u65f6\u95f4')     def pic_path(instance, filename):     #\u81ea\u5b9a\u4e49\u4fdd\u5b58\u8def\u5f84\u548c\u6587\u4ef6\u540d      # \u6e90\u6587\u4ef6\u540d\u540e\u7f00     ext = filename.split('.')[-1]     # \u6587\u4ef6\u540d     # new_name = datetime.now().strftime('%Y%m\/')+shortuuid.uuid()     # new_name =instance.id #\u65e0\u6548     new_name =      # \u62fc\u63a5\u6587\u4ef6\u540d\u548c\u540e\u7f00     path = new_name + '.' + ext     return path   <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"585887\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 111111111111 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             save \u4ee5\u540e\u5c31\u6709 id \u4e86\uff0c\u7136\u540e\u518d\u4fee\u6539\u6587\u4ef6\u8def\u5f84                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585888\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SingeeKing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u4ee5\u7528 post_save signal \u6539\u540d\u5b9e\u73b0\u3002\u5982\u679c\u662f\u60f3\u521b\u5efa\u9636\u6bb5\u4fbf\u547d\u540d\u4e3a ID \u662f\u4e0d\u53ef\u80fd\u7684 \u2014\u2014 \u56e0\u4e3a\u4fdd\u5b58\u4e4b\u524d\u8fd8\u6ca1\u6709 ID                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585889\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u4e00\u4e2a sequance \u6ca1\u6b21\u9700\u8981\u540d\u5b57\u90fd\u4ece seq \u53d6\u4e00\u4e2a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585890\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : emeab <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 redis \u81ea\u589e\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585891\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : emeab <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8fc7\u8fd8\u662f\u63a8\u8350\u7528\u96ea\u82b1\u7b97\u6cd5\u505a\u552f\u4e00\u540d\u5427 \u81ea\u589e\u610f\u4e49\u4e0d\u5927                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585892\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dolaxi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @emeab \u6211\u662f\u62c5\u5fc3\u6570\u636e\u91cf\u5927\u4e86\uff0c\u5982\u679c name \u592a\u590d\u6742\uff0c\u53c8\u6ca1\u6709\u4e00\u5b9a\u7684\u9012\u589e\uff0c\u6570\u636e\u5e93\u7d22\u5f15\u538b\u529b\u6bd4\u8f83\u5927                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585893\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : beastk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 hash \u5427\u81ea\u5df1\u751f\u6210\uff0c\u4e0d\u7528\u7b49\u81ea\u589e\uff0c\u6bd4\u5982\u65f6\u95f4\u6233\u2795\u968f\u673a\u6570\uff0c\u6216\u8005\u539f\u5b50\uff0c\u63d0\u524d\u751f\u6210\u597d\u5c31\u662f\u552f\u4e00 id \u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"585894\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Erroad <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65f6\u95f4\u6233+redis \u81ea\u589e+\u968f\u673a\u6570                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Django \u5982\u4f55\u7528\u81ea\u589e id \u4f5c&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\/89067"}],"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=89067"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/89067\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89067"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}