{"id":5915,"date":"2024-08-27T07:01:03","date_gmt":"2024-08-26T23:01:03","guid":{"rendered":""},"modified":"2024-08-27T07:01:03","modified_gmt":"2024-08-26T23:01:03","slug":"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5915.html","title":{"rendered":"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868"},"content":{"rendered":"
\n

1\u3001\u5b50\u67e5\u8be2\uff1a\u57fa\u4e8e\u5bf9\u8c61\u7684\u8de8\u8868\u67e5\u8be2 <\/h3>\n
\n \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868
\n \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868 <\/p>\n
\n
def<\/span> query(request): <\/span>\"\"\"<\/span> \u8de8\u8868\u67e5\u8be2\uff1a 1.\u57fa\u4e8e\u5bf9\u8c61\u67e5\u8be2 2.\u57fa\u4e8e\u53cc\u4e0b\u5212\u7ebf\u67e5\u8be2 3.\u805a\u5408\u3001\u5206\u7ec4\u67e5\u8be2 4. F Q \u67e5\u8be2 <\/span>\"\"\"<\/span> #<\/span> ----\u57fa\u4e8e\u5bf9\u8c61\u7684\u8de8\u8868\u67e5\u8be2\uff08\u5b50\u67e5\u8be2\uff09<\/span> #<\/span> 1.\u4e00\u5bf9\u591a\u67e5\u8be2<\/span> \"\"\"<\/span> # \u4e00\u5bf9\u591a\u67e5\u8be2 \u6b63\u5411\u67e5\u8be2:\u6309\u5b57\u6bb5 \u53cd\u5411\u67e5\u8be2:\u8868\u540d\u5c0f\u5199_set.all() book_obj.publish Book(\u5173\u8054\u5c5e\u6027:publish)\u5bf9\u8c61 --------------> Publish\u5bf9\u8c61 <-------------- publish_obj.book_set.all() # queryset <\/span>\"\"\"<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u74f6\u6885\u8fd9\u672c\u4e66\u7684\u51fa\u7248\u793e\u7684\u540d\u5b57<\/span> book_obj = Book.objects.filter(title='<\/span>\u74f6\u6885<\/span>'<\/span>).first() publish_obj <\/span>= book_obj.publish #<\/span> \u4e0e\u8fd9\u672c\u4e66\u5173\u8054\u7684\u51fa\u7248\u793e\u5bf9\u8c61<\/span> publish_name = publish_obj.name <\/span>print<\/span>(publish_name) #<\/span> \u5357\u4eac\u51fa\u7248\u793e<\/span> #<\/span> \u53cd\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u4eba\u6c11\u51fa\u7248\u793e\u51fa\u7248\u7684\u4e66\u7c4d\u540d\u79f0<\/span> publish_obj = Publish.objects.filter(name='<\/span>\u4eba\u6c11\u51fa\u7248\u793e<\/span>'<\/span>).first() books_obj <\/span>= publish_obj.book_set.all() <\/span>print<\/span>(books_obj) #<\/span> <QuerySet [<Book: \u6c34\u6d52\u4f20>, <Book: \u897f\u6e38\u8bb0>, <Book: \u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f>]><\/span> #<\/span> print(books_obj.title) #error 'QuerySet' object has no attribute 'title'<\/span> #<\/span> 2.\u591a\u5bf9\u591a<\/span> \"\"\"<\/span> # \u591a\u5bf9\u591a\u67e5\u8be2 \u6b63\u5411\u67e5\u8be2:\u6309\u5b57\u6bb5 \u53cd\u5411\u67e5\u8be2:\u8868\u540d\u5c0f\u5199_set.all() book_obj.authors.all() Book(\u5173\u8054\u5c5e\u6027:authors)\u5bf9\u8c61 ------------------------> Author\u5bf9\u8c61 <------------------------ author_obj.book_set.all() # queryset <\/span>\"\"\"<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u91d12\u74f6\u6885\u8fd9\u672c\u4e66\u7684\u6240\u6709\u4f5c\u8005<\/span> book_obj1 = Book.objects.filter(title='<\/span>\u91d12\u74f6\u6885<\/span>'<\/span>).first() book_obj2 <\/span>= Book.objects.filter(title='<\/span>\u91d12\u74f6\u6885<\/span>'<\/span>) <\/span>print<\/span>('<\/span>.first()<\/span>'<\/span>,book_obj1, type(book_obj1)) <\/span>print<\/span>('<\/span>\u65e0first()<\/span>'<\/span>,book_obj2,type(book_obj2)) authors_list <\/span>= book_obj.authors.all() <\/span>print<\/span>(authors_list) #<\/span> QuerySet\u5bf9\u8c61 <QuerySet [<Author: alex>, <Author: jack>]><\/span> for<\/span> author in<\/span> authors_list: <\/span>print<\/span>(author.name) <\/span>#<\/span> \u53cd\u5411\u67e5\u8be2\uff1a\u67e5\u8be2alex\u51fa\u7248\u8fc7\u7684\u6240\u6709\u4e66\u7c4d\u540d\u79f0<\/span> author_obj = Author.objects.filter(name='<\/span>alex<\/span>'<\/span>).first() books_list <\/span>= author_obj.book_set.all() <\/span>print<\/span>(books_list) <\/span>for<\/span> book in<\/span> books_list: <\/span>print<\/span>(book.title) <\/span>#<\/span> 3. \u4e00\u5bf9\u4e00<\/span> \"\"\"<\/span> # \u4e00\u5bf9\u4e00\u67e5\u8be2 \u6b63\u5411\u67e5\u8be2:\u6309\u5b57\u6bb5 \u53cd\u5411\u67e5\u8be2:\u8868\u540d\u5c0f\u5199 author.authordetail Author(\u5173\u8054\u5c5e\u6027:authordetail)\u5bf9\u8c61 ------------------------>AuthorDetail\u5bf9\u8c61 <------------------------ authordetail.author <\/span>\"\"\"<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a\u67e5\u8be2alex\u7684\u624b\u673a\u53f7<\/span> author_obj = Author.objects.filter(name='<\/span>alex<\/span>'<\/span>).first() phone <\/span>= author_obj.authordetail.telephone #<\/span> \u4e0eauthor\u5173\u8054\u7684authordetail\u5bf9\u8c61<\/span> print<\/span>(phone) <\/span>#<\/span> \u53cd\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u624b\u673a\u53f7\u4e3a110\u7684\u4f5c\u8005\u7684\u540d\u5b57\u548c\u5e74\u9f84<\/span> ad_obj = AuthorDetail.objects.filter(telephone=\"<\/span>110<\/span>\"<\/span>).first() name <\/span>= ad_obj.author.name #<\/span> \u5173\u8054\u7684\u5bf9\u8c61author<\/span> age = ad_obj.author.age <\/span>print<\/span>(name, age) <\/span>return<\/span> HttpResponse(\"<\/span>\u67e5\u8be2\u6210\u529f<\/span>\"<\/span>)<\/pre>\n<\/p><\/div>\n

Views\u4ee3\u7801<\/span>\n <\/div>\n

 <\/p>\n

\u3000\u30001.\u7b80\u4ecb<\/h4>\n

\u3000\u3000\u6838\u5fc3\uff1abook.authors.all()<\/p>\n

\n
\u5173\u952e\u70b9 \u4e00\u3001book_obj.publish <\/span>= Publish.objects.filter(id=book_obj.publish_id).first() \u4e8c\u3001book_obj.authors.all() \u5173\u952e\u70b9\uff1a book.authors.all() <\/span>#<\/span> \u4e0e\u8fd9\u672c\u4e66\u5173\u8054\u7684\u4f5c\u8005\u96c6\u5408<\/span> 1 book.id=3 2 book_authors id book_id author_id <\/span>3 3 1 4 3 2 3. author id name <\/span>1 alex <\/span>2 jack book_obj.authors.all() <\/span>-----> [alex,jack]<\/pre>\n<\/p><\/div>\n

 <\/p>\n

 \u3000\u3000\u6b63\u5411\u67e5\u8be2 \u53cd\u5411\u67e5\u8be2<\/p>\n

\n
A-B \u5173\u8054\u5c5e\u6027\u5728A\u8868\u4e2d \u6b63\u5411\u67e5\u8be2: A<\/span>------>B \u53cd\u5411\u67e5\u8be2: B<\/span>------>A<\/pre>\n<\/p><\/div>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

2\u3001\u4e00\u5bf9\u591a<\/span><\/h4>\n

 \u8bed\u6cd5<\/p>\n

\n
 #<\/span> \u4e00\u5bf9\u591a\u67e5\u8be2<\/span>  \u6b63\u5411\u67e5\u8be2:\u6309\u5b57\u6bb5 \u53cd\u5411\u67e5\u8be2:\u8868\u540d\u5c0f\u5199_set.all() book_obj.publish Book(\u5173\u8054\u5c5e\u6027:publish)\u5bf9\u8c61 <\/span>--------------> Publish\u5bf9\u8c61 <\/span><-------------- publish_obj.book_set.all() <\/span>#<\/span> queryset<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\u3000\u3000\u67e5\u8be2<\/p>\n

 <\/p>\n

\n
 #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u6885\u74f6jin\u8fd9\u672c\u4e66\u7684\u51fa\u7248\u793e\u7684\u540d\u5b57<\/span> book_obj = Book.objects.filter(title='<\/span>\u6885\u74f6jin<\/span>'<\/span>).first() publish_obj <\/span>= book_obj.publish #<\/span> \u4e0e\u8fd9\u672c\u4e66\u5173\u8054\u7684\u51fa\u7248\u793e\u5bf9\u8c61<\/span> publish_name = publish_obj.name <\/span>print<\/span>(publish_name) #<\/span> \u5357\u4eac\u51fa\u7248\u793e<\/span> 
#<\/span> \u53cd\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u4eba\u6c11\u51fa\u7248\u793e\u51fa\u7248\u7684\u4e66\u7c4d\u540d\u79f0<\/span> publish_obj = Publish.objects.filter(name='<\/span>\u4eba\u6c11\u51fa\u7248\u793e<\/span>'<\/span>).first() books_obj <\/span>= publish_obj.book_set.all() <\/span>print<\/span>(books_obj) #<\/span> <QuerySet [<Book: \u6c34\u6d52\u4f20>, <Book: \u897f\u6e38\u8bb0>, <Book: \u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f>]><\/span> #<\/span> print(books_obj.title) #error 'QuerySet' object has no attribute 'title'<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

3\u3001\u591a\u5bf9\u591a<\/h4>\n

\u89c4\u5219<\/p>\n

\n
 #<\/span> \u591a\u5bf9\u591a\u67e5\u8be2<\/span>  \u6b63\u5411\u67e5\u8be2:\u6309\u5b57\u6bb5 \u53cd\u5411\u67e5\u8be2:\u8868\u540d\u5c0f\u5199_set.all() book_obj.authors.all() Book(\u5173\u8054\u5c5e\u6027:authors)\u5bf9\u8c61 <\/span>------------------------> Author\u5bf9\u8c61 <\/span><------------------------ author_obj.book_set.all() <\/span>#<\/span> queryset<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\n
 #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u6885\u74f6jin\u8fd9\u672c\u4e66\u7684\u6240\u6709\u4f5c\u8005<\/span> book_obj = Book.objects.filter(title='<\/span>\u6885\u74f6jin<\/span>'<\/span>).first() authors_list <\/span>= book_obj.authors.all() <\/span>print<\/span>(authors_list) #<\/span> QuerySet\u5bf9\u8c61 <QuerySet [<Author: alex>, <Author: jack>]><\/span> for<\/span> author in<\/span> authors_list: <\/span>print<\/span>(author.name)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\n
 #<\/span> \u53cd\u5411\u67e5\u8be2\uff1a\u67e5\u8be2alex\u51fa\u7248\u8fc7\u7684\u6240\u6709\u4e66\u7c4d\u540d\u79f0<\/span> author_obj = Author.objects.filter(name='<\/span>alex<\/span>'<\/span>).first() books_list <\/span>= author_obj.book_set.all() <\/span>print<\/span>(books_list) <\/span>for<\/span> book in<\/span> books_list: <\/span>print<\/span>(book.title)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

4\u3001\u4e00\u5bf9\u4e00<\/h4>\n
\n
 #<\/span> \u4e00\u5bf9\u4e00\u67e5\u8be2<\/span>  \u6b63\u5411\u67e5\u8be2:\u6309\u5b57\u6bb5 \u53cd\u5411\u67e5\u8be2:\u8868\u540d\u5c0f\u5199 author.authordetail Author(\u5173\u8054\u5c5e\u6027:authordetail)\u5bf9\u8c61 <\/span>------------------------>AuthorDetail\u5bf9\u8c61 <\/span><------------------------ authordetail.author<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

\u67e5\u8be2<\/p>\n

\n
 #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a\u67e5\u8be2alex\u7684\u624b\u673a\u53f7<\/span> author_obj = Author.objects.filter(name='<\/span>alex<\/span>'<\/span>).first() phone <\/span>= author_obj.authordetail.telephone #<\/span> \u4e0eauthor\u5173\u8054\u7684authordetail\u5bf9\u8c61<\/span> print<\/span>(phone)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

\n
 #<\/span> \u53cd\u5411\u67e5\u8be2\uff1a\u67e5\u8be2\u624b\u673a\u53f7\u4e3a110\u7684\u4f5c\u8005\u7684\u540d\u5b57\u548c\u5e74\u9f84<\/span> ad_obj = AuthorDetail.objects.filter(telephone=\"<\/span>110<\/span>\"<\/span>).first() name <\/span>= ad_obj.author.name #<\/span> \u5173\u8054\u7684\u5bf9\u8c61author<\/span> age = ad_obj.author.age <\/span>print<\/span>(name, age)<\/pre>\n<\/p><\/div>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 <\/p>\n

 5\u3001\u57fa\u4e8e\u5bf9\u8c61\u8de8\u8868\u67e5\u8be2\u7684sql\u8bed\u53e5\uff1asetting\u4e2dlog\u65e5\u5fd7<\/h4>\n

 setting\u4e2d\u6dfb\u52a0logging\u65e5\u5fd7<\/p>\n

\n
LOGGING = { <\/span>'<\/span>version<\/span>'<\/span>: 1, <\/span>'<\/span>disable_existing_loggers<\/span>'<\/span>: False, <\/span>'<\/span>handlers<\/span>'<\/span>: { <\/span>'<\/span>console<\/span>'<\/span>:{ <\/span>'<\/span>level<\/span>'<\/span>:'<\/span>DEBUG<\/span>'<\/span>, <\/span>'<\/span>class<\/span>'<\/span>:'<\/span>logging.StreamHandler<\/span>'<\/span>, }, }, <\/span>'<\/span>loggers<\/span>'<\/span>: { <\/span>'<\/span>django.db.backends<\/span>'<\/span>: { <\/span>'<\/span>handlers<\/span>'<\/span>: ['<\/span>console<\/span>'<\/span>], <\/span>'<\/span>propagate<\/span>'<\/span>: True, <\/span>'<\/span>level<\/span>'<\/span>:'<\/span>DEBUG<\/span>'<\/span>, }, } }\u3000\u3000<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n
110 (<\/span>0.001) SELECT \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span>, \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>name<\/span>\"<\/span>, \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>age<\/span>\"<\/span>, \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>authordetail_id<\/span>\"<\/span> FROM \"<\/span>app01_author<\/span>\"<\/span> WHERE \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>name<\/span>\"<\/span> = '<\/span>alex<\/span>'<\/span> ORDER BY \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span> ASC LIMIT 1; args=('<\/span>alex<\/span>'<\/span>,) (<\/span>0.000) SELECT \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span>, \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>birthday<\/span>\"<\/span>, \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>telephone<\/span>\"<\/span>, \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>addr<\/span>\"<\/span> FROM \"<\/span>app01_authordetail<\/span>\"<\/span> WHERE \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span> = 1; args=(1,) (<\/span>0.001) SELECT \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span>, \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>birthday<\/span>\"<\/span>, \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>telephone<\/span>\"<\/span>, \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>addr<\/span>\"<\/span> FROM \"<\/span>app01_authordetail<\/span>\"<\/span> WHERE \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>telephone<\/span>\"<\/span> = 110 ORDER BY \"<\/span>app01_authordetail<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span> ASC LIMIT 1; args=(110,) alex <\/span>22 (<\/span>0.001) SELECT \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span>, \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>name<\/span>\"<\/span>, \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>age<\/span>\"<\/span>, \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>authordetail_id<\/span>\"<\/span> FROM \"<\/span>app01_author<\/span>\"<\/span> WHERE \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>authordetail_id<\/span>\"<\/span> = 1; args=(1,) [<\/span>04\/Jul\/2018 16:03:47] \"<\/span>GET \/app01\/query\/ HTTP\/1.1<\/span>\"<\/span> 200 12<\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

6.first()\u533a\u522b<\/h4>\n
\n
 #<\/span> \u67e5\u8be2\u6885\u74f6jin\u8fd9\u672c\u4e66\u7684\u6240\u6709\u4f5c\u8005<\/span> book_obj1 = Book.objects.filter(title='<\/span>\u6885\u74f6jin<\/span>'<\/span>).first() book_obj2 <\/span>= Book.objects.filter(title='<\/span>\u6885\u74f6jin<\/span>'<\/span>) <\/span>print<\/span>('<\/span>.first()<\/span>'<\/span>,book_obj1, type(book_obj1)) <\/span>print<\/span>('<\/span>\u65e0first()<\/span>'<\/span>,book_obj2,type(book_obj2))<\/pre>\n<\/p><\/div>\n

 <\/p>\n

\n
.first() \u6885\u74f6jin <class<\/span> '<\/span>app01.models.Book<\/span>'<\/span>> \u65e0first() <\/span><QuerySet [<Book: \u6885\u74f6jin>, <Book: \u6885\u74f6jin>]> <class<\/span> '<\/span>django.db.models.query.QuerySet<\/span>'<\/span>><\/pre>\n<\/p><\/div>\n

 <\/p>\n

2\u3001join\u67e5\u8be2\uff1a\u57fa\u4e8e\u53cc\u4e0b\u5212\u7ebf\u7684\u8de8\u8868\u67e5\u8be2<\/h3>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868
\n \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868 <\/p>\n
\n
def<\/span> joinquery(request): <\/span>#<\/span> ----\u57fa\u4e8e\u53cc\u4e0b\u5212\u7ebf\u7684\u8de8\u8868\u67e5\u8be2\uff08join\u67e5\u8be2\uff09<\/span> \"\"\"<\/span> \u6b63\u5411\u67e5\u8be2\u6309\u5b57\u6bb5\uff0c \u544a\u8bc9ORM\u5f15\u64cejoin\u54ea\u5f20\u8868 \u53cd\u5411\u67e5\u8be2\u6309\u8868\u540d\u5c0f\u5199\uff0c \u544a\u8bc9ORM\u5f15\u64cejoin\u54ea\u5f20\u8868 <\/span>\"\"\"<\/span> #<\/span> 1.\u4e00\u5bf9\u591a\u67e5\u8be2: # \u67e5\u8be2\u91d12\u74f6\u6885\u8fd9\u672c\u4e66\u7684\u51fa\u7248\u793e\u7684\u540d\u5b57<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a<\/span> ret = Book.objects.filter(title='<\/span>\u91d12\u74f6\u6885<\/span>'<\/span>).values('<\/span>publish__name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'publish__name': '\u5357\u4eac\u51fa\u7248\u793e'}]><\/span> #<\/span> \u53cd\u5411\u67e5\u8be2:<\/span> ret = Publish.objects.filter(book__title='<\/span>\u91d12\u74f6\u6885<\/span>'<\/span>).values('<\/span>name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'authors__name': 'alex'}, {'authors__name': 'jack'},<\/span> #<\/span> 2.\u591a\u5bf9\u591a \u67e5\u8be2\u91d12\u74f6\u6885\u8fd9\u672c\u4e66\u7684\u6240\u6709\u4f5c\u8005\u7684\u540d\u5b57<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7Book\u8868join\u4e0e\u5176\u5173\u8054\u7684Author\u8868,\u5c5e\u4e8e\u6b63\u5411\u67e5\u8be2\uff1a\u6309\u5b57\u6bb5authors\u901a\u77e5ORM\u5f15\u64cejoin book_author\u4e0eauthor\u8868<\/span> ret = Book.objects.filter(title='<\/span>\u91d12\u74f6\u6885<\/span>'<\/span>).values('<\/span>authors__name<\/span>'<\/span>) <\/span>print<\/span>(ret) <\/span>#<\/span> \u53cd\u5411\u67e5\u8be2<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7Author\u8868join\u4e0e\u5176\u5173\u8054\u7684Book\u8868\uff0c\u5c5e\u4e8e\u53cd\u5411\u67e5\u8be2\uff1a\u6309\u8868\u540d\u5c0f\u5199book\u901a\u77e5ORM\u5f15\u64cejoin book_authors\u4e0ebook\u8868<\/span> ret = Author.objects.filter(book__title='<\/span>\u91d12\u74f6\u6885<\/span>'<\/span>).values('<\/span>name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': 'alex'}, {'name': 'jack'}]><\/span> #<\/span> 3. \u4e00\u5bf9\u4e00 # \u67e5\u8be2alex\u7684\u624b\u673a\u53f7<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7Author\u8868join\u4e0e\u5176\u76f8\u5173\u8054\u7684AuthorDetail\u8868\uff0c\u5c5e\u4e8e\u6b63\u5411\u67e5\u8be2\uff1a\u6309\u5b57\u6bb5authordetail\u901a\u77e5ORM join AuthorDetail\u8868<\/span> ret = Author.objects.filter(name='<\/span>alex<\/span>'<\/span>).values('<\/span>authordetail__telephone<\/span>'<\/span>) <\/span>print<\/span>(ret) <\/span>#<\/span> \u53cd\u5411\u67e5\u8be2\uff1a<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7AuthorDetail\u8868join\u4e0e\u5176\u76f8\u5173\u8054\u7684Author\u8868\uff0c\u5c5e\u4e8e\u53cd\u5411\u67e5\u8be2\uff1a\u6309\u8868\u540d\u5c0f\u5199author\u901a\u77e5ORM join Author\u8868<\/span> ret = AuthorDetail.objects.filter(author__name='<\/span>alex<\/span>'<\/span>).values('<\/span>telephone<\/span>'<\/span>) <\/span>print<\/span>(ret) <\/span>return<\/span> HttpResponse('<\/span>join\u67e5\u8be2\u6210\u529f<\/span>'<\/span>)<\/pre>\n<\/p><\/div>\n

views\u4ee3\u7801<\/span>\n <\/div>\n

 <\/p>\n

 <\/p>\n

1\u3001\u4e00\u5bf9\u591a<\/h4>\n
\n
 #<\/span> 1.\u4e00\u5bf9\u591a\u67e5\u8be2: # \u67e5\u8be2\u6885ping\u91d1\u8fd9\u672c\u4e66\u7684\u51fa\u7248\u793e\u7684\u540d\u5b57<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a<\/span> ret = Book.objects.filter(title='<\/span>\u6885ping\u91d1<\/span>'<\/span>).values('<\/span>publish__name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'publish__name': '\u5357\u4eac\u51fa\u7248\u793e'}]><\/span> #<\/span> \u53cd\u5411\u67e5\u8be2:<\/span> ret = Publish.objects.filter(book__title='<\/span>\u6885ping\u91d1<\/span>'<\/span>).values('<\/span>name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'authors__name': 'alex'}, {'authors__name': 'jack'},<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\u3000\u3000\uff081\uff09pycharm\u7684sql\u67e5\u8be2<\/p>\n

\n
#<\/span>\u67e5\u8be2\u6885ping\u91d1\u8fd9\u672c\u4e66\u7684\u51fa\u7248\u793e\u7684\u540d\u5b57<\/span>  SELECT app01_publish.name FROM app01_book INNER JOIN app01_publish ON app01_book.publish_id <\/span>= app01_publish.nid WHERE app01_book.title<\/span>='<\/span>\u6885ping\u91d1<\/span>'<\/span><\/pre>\n<\/p><\/div>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u3000\u3000\uff082\uff09\u6b63\u5411\u67e5\u8be2\uff1a\u6b63\u5411\u67e5\u8be2\u6309\u5b57\u6bb5<\/p>\n

\u3000\u3000\u3000\u3000Book\u8868\u7684publish\u5173\u8054\u5b57\u6bb5\uff0c__\u53cc\u4e0b\u5212\u7ebf \u5173\u8054\u5230Publish\u8868\uff0c__name \u53d6\u51faPublish\u8868\u7684name\u5b57\u6bb5<\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n
(0.002<\/span>) SELECT \"<\/span>app01_publish<\/span>\"<\/span>.\"<\/span>name<\/span>\"<\/span> FROM \"<\/span>app01_book<\/span>\"<\/span> INNER JOIN <\/span>\"<\/span>app01_publish<\/span>\"<\/span> ON (<\/span>\"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>publish_id<\/span>\"<\/span> = \"<\/span>app01_publish<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span>) WHERE <\/span>\"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>title<\/span>\"<\/span> = '<\/span>\u6885ping\u91d1<\/span>'<\/span> LIMIT <\/span>21<\/span>; args=('<\/span>\u6885ping\u91d1<\/span>'<\/span>,)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u3000\u3000\uff083\uff09\u53cd\u5411\u67e5\u8be2\uff1a\u53cd\u5411\u67e5\u8be2\u6309\u8868\u540d\u5c0f\u5199<\/p>\n

\u3000\u3000\u3000\u3000Publish\u5173\u8054\u8868\u540d\u5c0f\u5199book\u8868\uff0c __title\u53d6\u51fabook\u8868\u7684title\u5b57\u6bb5\uff0c  .values \u53d6\u51faPublish\u8868\u7684\u503c<\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n
(0.001<\/span>) SELECT \"<\/span>app01_publish<\/span>\"<\/span>.\"<\/span>name<\/span>\"<\/span> FROM \"<\/span>app01_publish<\/span>\"<\/span> INNER JOIN \"<\/span>app01_book<\/span>\"<\/span> ON (<\/span>\"<\/span>app01_publish<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span> = \"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>publish_id<\/span>\"<\/span>) WHERE <\/span>\"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>title<\/span>\"<\/span> = '<\/span>\u6885ping\u91d1<\/span>'<\/span> LIMIT 21<\/span>; args=('<\/span>\u6885ping\u91d1<\/span>'<\/span>,)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

 2\u3001\u591a\u5bf9\u591a<\/h4>\n
\n
 #<\/span> 2.\u591a\u5bf9\u591a \u67e5\u8be2\u6885ping\u91d1\u8fd9\u672c\u4e66\u7684\u6240\u6709\u4f5c\u8005\u7684\u540d\u5b57<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7Book\u8868join\u4e0e\u5176\u5173\u8054\u7684Author\u8868,\u5c5e\u4e8e\u6b63\u5411\u67e5\u8be2\uff1a\u6309\u5b57\u6bb5authors\u901a\u77e5ORM\u5f15\u64cejoin book_author\u4e0eauthor\u8868<\/span> ret = Book.objects.filter(title='<\/span>\u6885ping\u91d1<\/span>'<\/span>).values('<\/span>authors__name<\/span>'<\/span>) <\/span>print<\/span>(ret) <\/span>#<\/span> \u53cd\u5411\u67e5\u8be2<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7Author\u8868join\u4e0e\u5176\u5173\u8054\u7684Book\u8868\uff0c\u5c5e\u4e8e\u53cd\u5411\u67e5\u8be2\uff1a\u6309\u8868\u540d\u5c0f\u5199book\u901a\u77e5ORM\u5f15\u64cejoin book_authors\u4e0ebook\u8868<\/span> ret = Author.objects.filter(book__title='<\/span>\u6885ping\u91d1<\/span>'<\/span>).values('<\/span>name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': 'alex'}, {'name': 'jack'}]><\/span><\/pre>\n<\/p><\/div>\n

\u3000\u3000<\/p>\n

\u3000\u3000sql\u8bed\u53e5<\/p>\n

\n
#<\/span> \u67e5\u8be2\u6885ping\u91d1\u8fd9\u672c\u4e66\u7684\u6240\u6709\u4f5c\u8005\u7684\u540d\u5b57\uff08join\uff09<\/span> SELECT app01_author.name FROM app01_book INNER JOIN app01_book_authors ON app01_book.nid <\/span>= app01_book_authors.book_id INNER JOIN app01_author ON app01_book_authors.author_id <\/span>= app01_author.nid<\/pre>\n<\/p><\/div>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u3000\u3000\uff081\uff09\u6b63\u5411\u67e5\u8be2<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 \u3000\u3000\uff082\uff09\u53cd\u5411\u67e5\u8be2<\/p>\n

\n
SELECT \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>name<\/span>\"<\/span> FROM \"<\/span>app01_book<\/span>\"<\/span> LEFT OUTER JOIN <\/span>\"<\/span>app01_book_authors<\/span>\"<\/span> ON (<\/span>\"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span> = \"<\/span>app01_book_authors<\/span>\"<\/span>.\"<\/span>book_id<\/span>\"<\/span>) LEFT OUTER JOIN <\/span>\"<\/span>app01_author<\/span>\"<\/span> ON (<\/span>\"<\/span>app01_book_authors<\/span>\"<\/span>.\"<\/span>author_id<\/span>\"<\/span> = \"<\/span>app01_author<\/span>\"<\/span>.\"<\/span>nid<\/span>\"<\/span>) WHERE \"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>title<\/span>\"<\/span> = '<\/span>\u6885ping\u91d1<\/span>'<\/span> LIMIT 21; args=('<\/span>\u6885ping\u91d1<\/span>'<\/span>,)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

\u63a8\u8350\u65b9\u5f0f:\u6b63\u5411\u67e5\u8be2\u77ed\u53e5<\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 3\u3001\u4e00\u5bf9\u4e00<\/h4>\n
\n
 #<\/span> 3. \u4e00\u5bf9\u4e00 # \u67e5\u8be2alex\u7684\u624b\u673a\u53f7<\/span> #<\/span> \u6b63\u5411\u67e5\u8be2\uff1a<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7Author\u8868join\u4e0e\u5176\u76f8\u5173\u8054\u7684AuthorDetail\u8868\uff0c\u5c5e\u4e8e\u6b63\u5411\u67e5\u8be2\uff1a\u6309\u5b57\u6bb5authordetail\u901a\u77e5ORM join AuthorDetail\u8868<\/span> ret = Author.objects.filter(name='<\/span>alex<\/span>'<\/span>).values('<\/span>authordetail__telephone<\/span>'<\/span>) <\/span>print<\/span>(ret) <\/span>#<\/span> \u53cd\u5411\u67e5\u8be2\uff1a<\/span> #<\/span> \u9700\u6c42\uff1a\u901a\u8fc7AuthorDetail\u8868join\u4e0e\u5176\u76f8\u5173\u8054\u7684Author\u8868\uff0c\u5c5e\u4e8e\u53cd\u5411\u67e5\u8be2\uff1a\u6309\u8868\u540d\u5c0f\u5199author\u901a\u77e5ORM join Author\u8868<\/span> ret = AuthorDetail.objects.filter(author__name='<\/span>alex<\/span>'<\/span>).values('<\/span>telephone<\/span>'<\/span>) <\/span>print<\/span>(ret)<\/pre>\n<\/p><\/div>\n

 <\/p>\n

\u3000\u3000\uff081\uff09\u6b63\u5411\u67e5\u8be2<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u3000\u3000\uff082\uff09\u53cd\u5411\u67e5\u8be2<\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 4\u3001\u8fde\u7eed\u8de8\u8868\uff1a\u57fa\u4e8e\u53cc\u4e0b\u5212\u7ebf\u7684<\/h4>\n
\n
telephone__startswith='110' # \u4ee5\u4ec0\u4e48\u5f00\u5934\u7684<\/code><\/pre>\n<\/p><\/div>\n
\n
 values('book__title', 'book__publish__name') #5\u5f20\u8868join\uff0c\u5b83\u7684\u4efb\u4f55\u5b57\u6bb5\u90fd\u53ef\u4ee5\u53d6\u51fa\u6765 <\/code><\/pre>\n<\/p><\/div>\n

\u3000\u3000<\/p>\n

\u3000\u3000<\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n
 #<\/span> \u65b9\u5f0f1\uff1a<\/span> #<\/span> \u624b\u673a\u53f7\u4ee5110\u5f00\u5934\u7684\u4f5c\u8005<\/span> author_name = Author.objects.filter(authordetail__telephone__startswith='<\/span>110<\/span>'<\/span>).values('<\/span>name<\/span>'<\/span>) <\/span>print<\/span>(author_name) #<\/span> <QuerySet [{'name': 'alex'}]><\/span> #<\/span> alex\u51fa\u7248\u8fc7\u7684\u6240\u6709\u4e66\u7c4d\u540d\u79f0<\/span> book_name = author_name.values('<\/span>book__title<\/span>'<\/span>) <\/span>print<\/span>(book_name) <\/span>#<\/span> \u4e66\u7c4d\u540d\u79f0\u5bf9\u5e94\u7684\u4e66\u7c4d\u51fa\u7248\u793e\u540d\u79f0<\/span> publish = author_name.values('<\/span>book__publish__name<\/span>'<\/span>) <\/span>print<\/span>(publish) <\/span>#<\/span> \u5408\u5e76\u9519\u8bef<\/span> #<\/span> list = Author.objects.filter(authordetail__telephone__startswith='110').values('name').values('book__title').values('book__publish__name')<\/span> #<\/span> print(list) # <QuerySet [{'book__publish__name': '\u4eba\u6c11\u51fa\u7248\u793e'}, {'book__publish__name': '\u5357\u4eac\u51fa\u7248\u793e'}]><\/span>  list <\/span>= Author.objects.filter(authordetail__telephone__startswith='<\/span>110<\/span>'<\/span>).values('<\/span>book__title<\/span>'<\/span>, '<\/span>book__publish__name<\/span>'<\/span>) <\/span>print<\/span>(list) #<\/span> <QuerySet [{'book__title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f', 'book__publish__name': '\u4eba\u6c11\u51fa\u7248\u793e'}, {'book__title': '\u6885ping\u91d1', 'book__publish__name': '\u5357\u4eac\u51fa\u7248\u793e'}]><\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n
 #<\/span> \u65b9\u5f0f2\uff1a<\/span> #<\/span> \u624b\u673a\u53f7\u4ee5110\u5f00\u5934\u7684\u4f5c\u8005\u51fa\u7248\u8fc7\u7684\u6240\u6709\u4e66\u7c4d<\/span> books = Book.objects.filter(authors__authordetail__telephone__startswith='<\/span>110<\/span>'<\/span>).values('<\/span>title<\/span>'<\/span>) <\/span>print<\/span>(books) #<\/span> <QuerySet [{'title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f'}, {'title': '\u6885ping\u91d1'}]><\/span> #<\/span> \u4e66\u7c4d\u51fa\u7248\u793e\u540d\u79f0<\/span> publishs = books.values('<\/span>publish__name<\/span>'<\/span>) <\/span>print<\/span>(publishs) #<\/span> <QuerySet [{'publish__name': '\u4eba\u6c11\u51fa\u7248\u793e'}, {'publish__name': '\u5357\u4eac\u51fa\u7248\u793e'}]><\/span>  list <\/span>= Book.objects.filter(authors__authordetail__telephone__startswith='<\/span>110<\/span>'<\/span>).values('<\/span>title<\/span>'<\/span>,'<\/span>publish__name<\/span>'<\/span>) <\/span>print<\/span>(list) #<\/span> <QuerySet [{'title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f', 'publish__name': '\u4eba\u6c11\u51fa\u7248\u793e'}, {'title': '\u6885ping\u91d1', 'publish__name': '\u5357\u4eac\u51fa\u7248\u793e'}]><\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

3\u3001\u805a\u5408\u67e5\u8be2<\/h3>\n
\n
 #<\/span> --> \u805a\u5408 aggregate:\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u5b57\u5178\uff0c\u4e0d\u518d\u662fqueryset <\/span> #<\/span> \u67e5\u8be2\u6240\u6709\u4e66\u7c4d\u7684\u5e73\u5747\u4ef7\u683c<\/span> from<\/span> django.db.models import<\/span> Avg, Max, Min, Count <\/span>#<\/span>ret = Book.objects.all().aggregate(Avg('price')) # {'price__avg': 150.0}<\/span> ret = Book.objects.all().aggregate(avg_price=Avg('<\/span>price<\/span>'<\/span>)) #<\/span> {'avg_price': 150.0}<\/span> print<\/span>(ret) ret <\/span>= Book.objects.all().aggregate(avg_price=Avg('<\/span>price<\/span>'<\/span>), max_price=Max('<\/span>price<\/span>'<\/span>), min_price=Min('<\/span>price<\/span>'<\/span>)) <\/span>print<\/span>(ret) #<\/span> {'avg_price': 150.0, 'max_price': Decimal('200.00'), 'min_price': Decimal('100.00')}<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\n
SELECT AVG(\"<\/span>app01_book<\/span>\"<\/span>.\"<\/span>price<\/span>\"<\/span>) AS \"<\/span>price__avg<\/span>\"<\/span> FROM <\/span>\"<\/span>app01_book<\/span>\"<\/span>;<\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

 <\/p>\n

4\u3001\u5206\u7ec4\u67e5\u8be2<\/h3>\n
\n
# -------- \u5206\u7ec4\u67e5\u8be2 annotate, \u8fd4\u56de\u503c\u4f9d\u65e7\u662f\u4e2aqueryset <\/code><\/pre>\n<\/p><\/div>\n

\u3000\u3000<\/p>\n

\u3000\u3000\uff081\uff09\u5355\u8868\u5206\u7ec4\u67e5\u8be2<\/h4>\n

\u601d\u8003<\/p>\n

\n
 \"\"\"<\/span> \u5355\u8868\u7684\u5206\u7ec4\u67e5\u8be2: \u67e5\u8be2\u6bcf\u4e00\u4e2a\u90e8\u95e8\u540d\u79f0\u4ee5\u53ca\u5bf9\u5e94\u7684\u5458\u5de5\u6570 emp: id name age salary dep 1 alex 12 2000 \u9500\u552e\u90e8 2 egon 22 3000 \u4eba\u4e8b\u90e8 3 wen 22 5000 \u4eba\u4e8b\u90e8 sql : select Count(id) from emp group by dep; \u601d\u8003:\u5982\u4f55\u7528ORM\u8bed\u6cd5\u8fdb\u884c\u5206\u7ec4\u67e5\u8be2?<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

\u8bed\u6cd5<\/p>\n

\n
 #<\/span> \u5355\u8868\u5206\u7ec4\u67e5\u8be2\u7684ORM\u8bed\u6cd5: \u5355\u8868\u6a21\u578b.objects.values(\"group by\u7684\u5b57\u6bb5\").annotate(\u805a\u5408\u51fd\u6570(\"\u7edf\u8ba1\u5b57\u6bb5\"))<\/span> #<\/span> \u5728\u5355\u8868\u5206\u7ec4\u4e0b,\u6309\u7740\u4e3b\u952e\u8fdb\u884cgroup by\u662f\u6ca1\u6709\u4efb\u4f55\u610f\u4e49\u7684.<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\u7ec3\u4e60<\/p>\n

\n
 #<\/span> \u5355\u8868\u5206\u7ec4\u67e5\u8be2\uff1a<\/span> #<\/span> 1.\u67e5\u8be2\u6bcf\u4e00\u4e2a\u90e8\u95e8\u7684\u540d\u79f0\u4ee5\u53ca\u5458\u5de5\u7684\u5e73\u5747\u85aa\u6c34<\/span> #<\/span> select avg(salary) from emp group by dep<\/span>  ret <\/span>= Emp.objects.values('<\/span>dep<\/span>'<\/span>).annotate(Avg('<\/span>salary<\/span>'<\/span>)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'dep': '\u4fdd\u5b89\u90e8', 'salary__avg': 20000.0}, {'dep': '\u6559\u5b66\u90e8', 'salary__avg': 12500.0}]><\/span> #<\/span> 2.\u67e5\u8be2\u6bcf\u4e00\u4e2a\u7701\u4efd\u7684\u540d\u79f0\u4ee5\u53ca\u5458\u5de5\u6570<\/span> ret = Emp.objects.values('<\/span>province<\/span>'<\/span>).annotate(count=Count('<\/span>id<\/span>'<\/span>)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'province': '\u5c71\u4e1c\u7701', 'count': 2}, {'province': '\u6cb3\u5317\u7701', 'count': 1}]><\/span> #<\/span> 3.\u8865\u5145\u77e5\u8bc6\u70b9<\/span> ret = Emp.objects.all() <\/span>print<\/span>(ret) #<\/span> select * from emp<\/span> ret = Emp.objects.values('<\/span>name<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> select name from emp<\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\u3000\u3000<\/p>\n

\u3000\u3000\uff082\uff09\u8de8\u8868\u5206\u7ec4\u67e5\u8be2<\/h4>\n

\u601d\u8003<\/p>\n

\n
 \u8de8\u8868\u7684\u5206\u7ec4\u67e5\u8be2: Book\u8868 id title date price publish_id <\/span>1<\/span> \u7ea2\u697c\u68a6 2012<\/span>-12<\/span>-12<\/span> 101<\/span> 1<\/span> 2<\/span> \u897f\u6e38\u8bb0 2012<\/span>-12<\/span>-12<\/span> 101<\/span> 1<\/span> 3<\/span> \u4e09\u56fd\u6f14\u7ece 2012<\/span>-12<\/span>-12<\/span> 101<\/span> 1<\/span> 4<\/span> \u91d12\u74f6\u6885 2012<\/span>-12<\/span>-12<\/span> 301<\/span> 2<\/span> Publish\u8868 id name addr email <\/span>1<\/span> \u4eba\u6c11\u51fa\u7248\u793e \u5317\u4eac 123<\/span>@.com <\/span>2<\/span> \u5357\u4eac\u51fa\u7248\u793e \u5357\u4eac 345<\/span>@163<\/span>.com \u5206\u7ec4\u67e5\u8be2sql: <\/span>select<\/span> publish.name,Count(\"<\/span>title<\/span>\"<\/span>) from<\/span> Book inner join Publish on book.publish_id=publish.id group by publish.id,publish.name,publish.addr,publish.email \u601d\u8003:\u5982\u4f55\u7528ORM\u8bed\u6cd5\u8fdb\u884c\u8de8\u8868\u5206\u7ec4\u67e5\u8be2 <\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

 <\/p>\n

\u8bed\u6cd5<\/p>\n

\n
 5 \u603b\u7ed3: <\/span>#<\/span> \u603b\u7ed3 \u8de8\u8868\u7684\u5206\u7ec4\u67e5\u8be2\u7684\u6a21\u578b:<\/span> #<\/span> \u6bcf\u4e00\u4e2a\u540e\u7684\u8868\u6a21\u578b.objects.values(\"pk\").annotate(\u805a\u5408\u51fd\u6570(\u5173\u8054\u8868__\u7edf\u8ba1\u5b57\u6bb5)).values(\"\u8868\u6a21\u578b\u7684\u6240\u6709\u5b57\u6bb5\u4ee5\u53ca\u7edf\u8ba1\u5b57\u6bb5\") # \u63a8\u8350pk\u5b57\u6bb5\u67e5\u627e<\/span> #<\/span> \u6bcf\u4e00\u4e2a\u540e\u7684\u8868\u6a21\u578b.objects.annotate(\u805a\u5408\u51fd\u6570(\u5173\u8054\u8868__\u7edf\u8ba1\u5b57\u6bb5)).values(\"\u8868\u6a21\u578b\u7684\u6240\u6709\u5b57\u6bb5\u4ee5\u53ca\u7edf\u8ba1\u5b57\u6bb5\")<\/span> \"\"\"<\/span><\/pre>\n<\/p><\/div>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 <\/p>\n

\u8de8\u8868\u67e5\u8be2\u65b9\u5f0f1<\/p>\n

\n
 #<\/span> \u793a\u4f8b1\uff1a\u67e5\u8be2\u6bcf\u4e2a\u51fa\u7248\u793e\u7684\u540d\u79f0\u4ee5\u53ca\u51fa\u7248\u7684\u4e66\u7c4d\u7684\u4e2a\u6570<\/span> ret = Publish.objects.values('<\/span>nid<\/span>'<\/span>).annotate(count=Count('<\/span>book__title<\/span>'<\/span>)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'nid': 1, 'count': 3}, {'nid': 2, 'count': 3}, {'nid': 3, 'count': 0}, {'nid': 4, 'count': 0}]><\/span>  ret <\/span>= Publish.objects.values('<\/span>name<\/span>'<\/span>).annotate(count=Count('<\/span>book__title<\/span>'<\/span>)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': '\u4eba\u6c11\u51fa\u7248\u793e', 'count': 3}, {'name': '\u5357\u4eac\u51fa\u7248\u793e', 'count': 3}]><\/span> #<\/span> \u63a8\u8350\u4e3b\u952epk\u67e5\u627e<\/span> Publish.objects.values('<\/span>pk<\/span>'<\/span>).annotate(c=Count('<\/span>book__title<\/span>'<\/span>)).values('<\/span>name<\/span>'<\/span>, '<\/span>c<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': '\u4eba\u6c11\u51fa\u7248\u793e', 'count': 3}, {'name': '\u5357\u4eac\u51fa\u7248\u793e', 'count': 3}]><\/span> #<\/span> \u793a\u4f8b2\uff1a\u67e5\u8be2\u6bcf\u4e00\u4e2a\u4f5c\u8005\u7684\u540d\u5b57\u4ee5\u53ca\u51fa\u7248\u8fc7\u7684\u4e66\u7c4d\u7684\u6700\u9ad8\u4ef7\u683c<\/span> ret = Author.objects.values('<\/span>pk<\/span>'<\/span>).annotate(max_price=Max('<\/span>book__price<\/span>'<\/span>)).values('<\/span>name<\/span>'<\/span>, '<\/span>max_price<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': 'alex', 'max_price': Decimal('200.00')}, {'name': 'jack', 'max_price': Decimal('200.00')}]><\/span> #<\/span> \u793a\u4f8b3: \u67e5\u8be2\u6bcf\u4e00\u4e2a\u4e66\u7c4d\u7684\u540d\u79f0\u4ee5\u53ca\u5bf9\u5e94\u7684\u4f5c\u8005\u4e2a\u6570<\/span> ret = Book.objects.values('<\/span>pk<\/span>'<\/span>).annotate(c=Count('<\/span>authors__nid<\/span>'<\/span>)).values('<\/span>title<\/span>'<\/span>,'<\/span>c<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'title': '\u6c34\u6d52\u4f20', 'c': 0}, {'title': '\u897f\u6e38\u8bb0', 'c': 0}, {'title': '\u7ea2\u697c\u68a6', 'c': 0}, {'title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f', 'c': 2}, {'title': '\u91d12\u74f6\u6885', 'c': 2}, {'title': '\u91d12\u74f6\u6885', 'c': 0}]><\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u5206\u7ec4\u67e5\u8be2 group by\u6240\u6709\u7684\u5b57\u6bb5\uff0c\u6ca1\u6709\u610f\u4e49<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u8de8\u8868\u67e5\u8be2\u65b9\u5f0f2<\/p>\n

\n
 #<\/span> ---------\u8de8\u8868\u5206\u7ec4\u67e5\u8be2\u7684\u53e6\u4e00\u79cd\u73a9\u6cd5 ------------<\/span> #<\/span> \u793a\u4f8b1\uff1a\u67e5\u8be2\u6bcf\u4e2a\u51fa\u7248\u793e\u7684\u540d\u79f0\u4ee5\u53ca\u51fa\u7248\u7684\u4e66\u7c4d\u7684\u4e2a\u6570<\/span> ret = Publish.objects.all().annotate(c=Count('<\/span>book__title<\/span>'<\/span>)).values('<\/span>name<\/span>'<\/span>,'<\/span>c<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': '\u4eba\u6c11\u51fa\u7248\u793e', 'c': 3}, {'name': '\u5357\u4eac\u51fa\u7248\u793e', 'c': 3}, {'name': '\u4eba\u6c11\u51fa\u7248\u793e', 'c': 0}, {'name': '\u5357\u4eac\u51fa\u7248\u793e', 'c': 0}]><\/span> #<\/span> value\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u53d6\u51fa\u6765\uff1f\u53d6\u51fa\u6765\u7684\u662f\u5bf9\u8c61<\/span> ret = Publish.objects.values('<\/span>nid<\/span>'<\/span>).annotate(c=Count('<\/span>book__title<\/span>'<\/span>)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'nid': 1, 'c': 3}, {'nid': 2, 'c': 3}, {'nid': 3, 'c': 0}, {'nid': 4, 'c': 0}]><\/span> #<\/span> values\u53ef\u4ee5\u53d6\u51faPublish\u8868\u7684\u6bcf\u4e2a\u5b57\u6bb5 + \u805a\u5408\u5b57\u6bb5<\/span> ret = Publish.objects.values('<\/span>nid<\/span>'<\/span>).annotate(c=Count('<\/span>book__title<\/span>'<\/span>)).values() <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'nid': 1, 'name': '\u4eba\u6c11\u51fa\u7248\u793e', 'city': 'beijing', 'email': '123@.com', 'c': 3}, {'nid': 2, 'name': '\u5357\u4eac\u51fa\u7248\u793e', 'city': 'nanjing', 'email': '456@.com', 'c': 3}, ]><\/span><\/pre>\n<\/p><\/div>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\u7ec3\u4e60<\/p>\n

\n
 #<\/span> ########## \u7ec3\u4e60#############<\/span> #<\/span> \u6bcf\u4e00\u4e2a\u540e\u7684\u8868\u6a21\u578b.objects.values(\"pk\").annotate(\u805a\u5408\u51fd\u6570(\u5173\u8054\u8868__\u7edf\u8ba1\u5b57\u6bb5)).values(\"\u8868\u6a21\u578b\u7684\u6240\u6709\u5b57\u6bb5\u4ee5\u53ca\u7edf\u8ba1\u5b57\u6bb5\") # \u63a8\u8350pk\u5b57\u6bb5\u67e5\u627e<\/span> #<\/span> \u7edf\u8ba1\u6bcf\u4e00\u672c\u4ee5py\u5f00\u5934\u7684\u4e66\u7c4d\u7684\u4f5c\u8005\u4e2a\u6570\uff1a<\/span> #<\/span>ret = Book.objects.values('pk').annotate(c=Count('authors__nid')).filter(title__startswith='py').values('c')<\/span> ret = Book.objects.filter(title__startswith='<\/span>\u91d1<\/span>'<\/span>).values('<\/span>pk<\/span>'<\/span>).annotate(c=Count('<\/span>authors__nid<\/span>'<\/span>)).values('<\/span>title<\/span>'<\/span>,'<\/span>c<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'name': 'alex', 'book__title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f'}, {'name': 'alex', 'book__title': '\u91d12\u74f6\u6885'}, {'name': 'jack', 'book__title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f'}, {'name': 'jack', 'book__title': '\u91d12\u74f6\u6885'}]><\/span> #<\/span> \u7edf\u8ba1\u4e0d\u6b62\u4e00\u4e2a\u4f5c\u8005\u7684\u56fe\u4e66<\/span> ret = Author.objects.values('<\/span>pk<\/span>'<\/span>).annotate(Count('<\/span>book__nid<\/span>'<\/span>)).values('<\/span>name<\/span>'<\/span>,'<\/span>book__title<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'book__title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f'}, {'book__title': '\u91d12\u74f6\u6885'}, {'book__title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f'}, {'book__title': '\u91d12\u74f6\u6885'}]><\/span>  ret <\/span>= Book.objects.values('<\/span>pk<\/span>'<\/span>).annotate(c=Count('<\/span>authors__name<\/span>'<\/span>)).filter(c__gt=1).values('<\/span>title<\/span>'<\/span>,'<\/span>c<\/span>'<\/span>) <\/span>print<\/span>(ret) #<\/span> <QuerySet [{'title': '\u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f', 'c': 2}, {'title': '\u91d12\u74f6\u6885', 'c': 2}]><\/span><\/pre>\n<\/p><\/div>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 <\/p>\n

 <\/p>\n

5\u3001F\u67e5\u8be2 Q\u67e5\u8be2<\/h3>\n

\u3000\u3000\uff081\uff09\u6dfb\u52a0\u5b57\u6bb5\u7684\u65f6\u5019\u8981\u6307\u5b9a\u9ed8\u8ba4\u503c<\/h4>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 \u6dfb\u52a0\u6570\u636e<\/p>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n

 \u3000\uff082\uff09F\u67e5\u8be2\uff1a\u5927\u4e8e\uff0c+1<\/h4>\n
\n
#<\/span>### F\u67e5\u8be2\u4e0eQ\u67e5\u8be2<\/span> #<\/span>\u793a\u4f8b1\uff1a \u8bc4\u8bba\u6570\u5927\u4e8e\u9605\u8bfb\u6570\u7684\u4e66\u7c4d<\/span> #<\/span> Book.objects.filter(comment_num__gt=read_num)<\/span> from<\/span> django.db.models import<\/span> F ret <\/span>= Book.objects.filter(comment_num__gt=F('<\/span>read_num<\/span>'<\/span>)) <\/span>print<\/span>(ret) <\/span>#<\/span> \u793a\u4f8b2\uff1a\u6240\u6709\u4e66\u7c4d\u7684\u4ef7\u683c+1<\/span> #<\/span> Book.objects.all().update(price+=1)<\/span> #<\/span> Book.objects.all().update(price=price+1)<\/span> Book.objects.all().update(price=F('<\/span>price<\/span>'<\/span>)+1)
<\/span><\/pre>\n<\/p><\/div>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 \uff083\uff09Q\u67e5\u8be2 \u4e0e\u6216\u975e<\/h4>\n
\n
 #<\/span> \u4e0e\u6216\u975e<\/span> from<\/span> django.db.models import<\/span> Q <\/span>#<\/span> \u4e0e<\/span> ret1 = Book.objects.filter(title='<\/span>\u6c34\u6d52\u4f20<\/span>'<\/span>, price=106) <\/span>print<\/span>(ret1) #<\/span> <QuerySet [<Book: \u6c34\u6d52\u4f20>]><\/span> ret2 = Book.objects.filter(Q(title='<\/span>\u6c34\u6d52\u4f20<\/span>'<\/span>) & Q(price=106)) <\/span>print<\/span>(ret2) #<\/span> <QuerySet [<Book: \u6c34\u6d52\u4f20>]><\/span> #<\/span> \u6216<\/span> ret = Book.objects.filter(Q(title='<\/span>\u7ea2\u697c\u68a6<\/span>'<\/span>) | Q(price=106)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [<Book: \u6c34\u6d52\u4f20>, <Book: \u897f\u6e38\u8bb0>, <Book: \u7ea2\u697c\u68a6>, <Book: \u91d12\u74f6\u6885>]><\/span> #<\/span> \u975e<\/span> ret = Book.objects.filter(~Q(price=106)) <\/span>print<\/span>(ret) #<\/span> <QuerySet [<Book: \u7ea2\u697c\u68a6>, <Book: \u5927\u8bdd\u8bbe\u8ba1\u6a21\u5f0f>, <Book: \u91d12\u74f6\u6885>]><\/span> #<\/span> Book.objects.filter(comment_num__gt=100, ~(Q(title='\u7ea2\u697c\u68a6') | Q(price=106))) # Q\u67e5\u8be2\u9700\u8981\u653e\u5230\u6700\u540e\u9762<\/span> Book.objects.filter(~(Q(title='<\/span>\u7ea2\u697c\u68a6<\/span>'<\/span>)|Q(price=106)),comment_num__gt=100)<\/pre>\n<\/p><\/div>\n

\"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868 <\/p>\n

 \"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u8868<\/p>\n

 <\/p>\n<\/div>\n

\u8f6c\u8f7d\u4e8e:https:\/\/www.cnblogs.com\/venicid\/p\/9261370.html<\/p>\n","protected":false},"excerpt":{"rendered":"orical\u591a\u8868\u67e5\u8be2_\u591a\u4e2a\u8868\u683c\u6c47\u603b\u5230\u4e00\u4e2a\u88681\u3001\u5b50\u67e5\u8be2\uff1a\u57fa\u4e8e\u5bf9\u8c61\u7684\u8de8\u8868\u67e5\u8be2defquery(request):\"\"\"\u8de8\u8868\u67e5\u8be2\uff1a1.\u57fa\u4e8e\u5bf9\u8c61\u67e5\u8be22.\u57fa\u4e8e\u53cc...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5915"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5915"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5915\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}