{"id":746,"date":"2019-02-03T18:52:55","date_gmt":"2019-02-03T09:52:55","guid":{"rendered":"https:\/\/www.nblog09.com\/w\/?p=746"},"modified":"2021-11-11T17:34:15","modified_gmt":"2021-11-11T08:34:15","slug":"django-limit","status":"publish","type":"post","link":"https:\/\/www.nblog09.com\/w\/2019\/02\/03\/django-limit\/","title":{"rendered":"Django\u306e\u30e2\u30c7\u30eb\u3067Limit,Offset,filter\u3092\u5229\u7528\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u306e\u7d5e\u308a\u8fbc\u307f\u3001filter\u3067\u306e\u6761\u4ef6\u6307\u5b9a\u306e\u65b9\u6cd5\u307e\u3068\u3081"},"content":{"rendered":"<h2 class=\"title-border\"><strong>Django\u306e\u30e2\u30c7\u30eb\u3092\u7528\u3044\u305f\u5024\u306e\u53d6\u5f97(all,limit,offset,filter)<\/strong><\/h2>\n<p>Django\u306e\u30e2\u30c7\u30eb\u3067\u306f\u3001all\u3092\u7528\u3044\u3066\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u53d6\u5f97\u3059\u308b\u304c\u3001\u4e00\u90e8\u3060\u3051\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u95a2\u6570\u3092\u8a18\u8ff0\u3059\u308b\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u5024\u3092\u4e00\u90e8\u53d6\u308a\u51fa\u3059[:]<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nimport os<br \/>\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", 'Project.settings') <strong># django\u306eDB\u63a5\u7d9a\u8a2d\u5b9a\u8aad\u307f\u8fbc\u307f<\/strong><\/p>\n<p>import django<br \/>\ndjango.setup() <strong># django\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/strong><\/p>\n<p>from app.models import User<\/p>\n<p><strong># \"select * from user\"\u304c\u5b9f\u884c\u3055\u308c\u3001\u5168\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97<\/strong><br \/>\nuser_list = User.objects.all()<br \/>\n<strong># \"select * from user limit 3\"\u304c\u5b9f\u884c\u3055\u308c\u30013\u3064\u3060\u3051\u30ec\u30b3\u30fc\u30c9\u304c\u8fd4\u3055\u308c\u308b<\/strong><br \/>\nuser_list = User.objects.all()[:3]<br \/>\n<strong># \"select * from user limit 1 offset 2\"\u304c\u5b9f\u884c\u3055\u308c\u3001\u6700\u521d\u304b\u30892\u3064\u98db\u3070\u3057\u30661\u3064\u3060\u3051\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u8fd4\u3055\u308c\u308b<\/strong><br \/>\nuser_list = User.objects.all()[2:3]<br \/>\n<strong># User\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e10\u756a\u76ee\u307e\u3067\u306e1\u3064\u98db\u3070\u3057\u306e\u914d\u5217\u304c\u8fd4\u3055\u308c\u308b<\/strong><br \/>\nuser_list = User.objects.all()[:10:2]\n<\/div>\n<\/div>\n<p>\u307e\u305f\u3001all()\u3067\u306a\u304ffilter\u3092\u7528\u3044\u308b\u3068\u3001\u5024\u306e\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u3001\u30e2\u30c7\u30eb\u304b\u3089\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8\u3092\u8fd4\u3059\u3053\u3068\u3082\u3067\u304d\u308b\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>filter\u306e\u30b5\u30f3\u30d7\u30eb(=,&lt;,&gt;,like,and,or)<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nimport os<br \/>\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", 'ProTwo.settings')<\/p>\n<p>import django<br \/>\ndjango.setup()<\/p>\n<p>from appTwo.models import User<\/p>\n<p><strong># select * from user where first_name = 'Taro'\u304c\u5b9f\u884c\u3055\u308c\u308b<\/strong><br \/>\nuser_list = User.objects.filter(first_name='Taro')<\/p>\n<p> <strong># age\u304c10\u4ee5\u4e0b\u306e\u3082\u306e\u3060\u3051\u3092\u53d6\u5f97(select * from user where age &lt;= 10\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(age__lte=10)<\/p>\n<p><strong># age\u304c10\u4ee5\u4e0a\u306e\u3082\u306e\u3060\u3051\u3092\u53d6\u5f97(select * from user where age &gt;= 10\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(age__gte=10) <\/p>\n<p><strong> # age\u304c10\u3088\u308a\u5c0f\u3055\u3044\u306e\u3082\u306e\u3060\u3051\u3092\u53d6\u5f97(select * from user where age &lt; 10\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(age__lt=10)<br \/>\n<strong># age\u304c10\u3088\u308a\u5927\u304d\u3044\u306e\u3082\u306e\u3060\u3051\u3092\u53d6\u5f97(select * from user where age &gt; 10\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(age__gt=10)<\/p>\n<p><strong># first_name\u306bT\u3092\u542b\u3080\u3082\u306e\u3092\u53d6\u5f97(select * from user where first_name = '%T%'\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(first_name__contains='T')<br \/>\n<strong># first_name\u304cT\u3067\u59cb\u307e\u308b\u3082\u306e\u3092\u53d6\u5f97(select * from user where first_name = 'T%'\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(first_name__startswith='T')<br \/>\n<strong># first_name\u304cT\u3067\u7d42\u308f\u308b\u3082\u306e\u3092\u53d6\u5f97(select * from user where first_name = '%T'\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(first_name__endswith='T')<\/p>\n<p><strong># age\u304c32\u4ee5\u4e0b\u304b\u3064\u3001first_name\u304cT\u3067\u7d42\u308f\u308b\u3082\u306e\u3092\u53d6\u5f97(select * from user where age &lt;= 32 and first_name = '%T'\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(first_name__endswith='T', age__lte=32)<\/p>\n<p>from django.db.models import Q<br \/>\n<strong># age\u304c32\u4ee5\u4e0b\u307e\u305f\u306f\u3001first_name\u304cT\u3067\u7d42\u308f\u308b\u3082\u306e\u3092\u53d6\u5f97(select * from user where age &lt;= 32 or first_name = '%T'\u3092\u5b9f\u884c)<\/strong><br \/>\nuser_list = User.objects.filter(Q(first_name__endswith='T')| Q(age__lte=32))\n<\/div>\n<\/div>\n<div class=\"django-adsense\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Django\u306e\u30e2\u30c7\u30eb\u3092\u7528\u3044\u305f\u5024\u306e\u53d6\u5f97(all,limit,offset,filter) Django\u306e\u30e2\u30c7\u30eb\u3067\u306f\u3001all\u3092\u7528\u3044\u3066\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u53d6\u5f97\u3059\u308b\u304c\u3001\u4e00\u90e8\u3060\u3051\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3002 \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u95a2\u6570\u3092\u8a18\u8ff0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":386,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uag_custom_page_level_css":"","_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[121,219],"tags":[140,122,142,141,14],"class_list":{"0":"post-746","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-django","8":"category-it-programming","9":"tag-all","10":"tag-django","11":"tag-filter","12":"tag-limit","13":"tag-python","14":"entry"},"uagb_featured_image_src":{"full":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",853,480,false],"thumbnail":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480-150x150.jpg",150,150,true],"medium":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480-768x432.jpg",768,432,true],"large":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",853,480,false],"1536x1536":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",853,480,false],"2048x2048":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",853,480,false],"home-middle":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",622,350,false],"home-top":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",746,420,false],"sidebar-thumbnail":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2019\/01\/night-196431__480.jpg",100,56,false]},"uagb_author_info":{"display_name":"9nmatsumoto","author_link":"https:\/\/www.nblog09.com\/w\/author\/9nmatsumoto\/"},"uagb_comment_info":1,"uagb_excerpt":"Django\u306e\u30e2\u30c7\u30eb\u3092\u7528\u3044\u305f\u5024\u306e\u53d6\u5f97(all,limit,offset,filter) Django\u306e\u30e2\u30c7\u30eb\u3067&hellip;","_links":{"self":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/comments?post=746"}],"version-history":[{"count":18,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":3787,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/746\/revisions\/3787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media\/386"}],"wp:attachment":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media?parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/categories?post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/tags?post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}