... コアを使用してください。これは、好きなだけ深くできます。制限はありません。たとえば: >>> r . article_set . filter ( headline__startswith = "This" ) <QuerySet [<Article: This is a test>]> # Find all Articles for any Reporter whose first name is "John". >>> Art ... objects . filter ( article = a ) <QuerySet [<Reporter: John Smith>]> >>> Reporter . objects . filter ( article__headline__startswith = "This" ) <QuerySet [<Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>]> >>> Reporter . objects . fi ... lter ( article__headline__startswith = "This" ) . distinct () <QuerySet [<Reporter: John Smith>]> 逆方向のカウントは distinct() と連動して動作します: >>> Repor ... ... コアを使用してください。これは、好きなだけ深くできます。制限はありません。たとえば: >>> r . article_set . filter ( headline__startswith = "This" ) <QuerySet [<Article: This is a test>]> # Find all Articles for any Reporter whose first name is "John". >>> Art ... objects . filter ( article = a ) <QuerySet [<Reporter: John Smith>]> >>> Reporter . objects . filter ( article__headline__startswith = "This" ) <QuerySet [<Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>]> >>> Reporter . objects . fi ... lter ( article__headline__startswith = "This" ) . distinct () <QuerySet [<Reporter: John Smith>]> 逆方向のカウントは distinct() と連動して動作します: >>> Repor ... ... jango lets you build web apps easily>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publications__title__startswith = "Science" ) <QuerySet [<Article: NASA uses Python>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publi ... cations__title__startswith = "Science" ) . distinct () <QuerySet [<Article: NASA uses Python>]> count() 関数は distinct() も尊重します: >>> Article . ... objects . filter ( publications__title__startswith = "Science" ) . count () 2 >>> Article . objects . filter ( publications__title__startswith = "Science" ) . distinct () . ... ... jango lets you build web apps easily>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publications__title__startswith = "Science" ) <QuerySet [<Article: NASA uses Python>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publi ... cations__title__startswith = "Science" ) . distinct () <QuerySet [<Article: NASA uses Python>]> count() 関数は distinct() も尊重します: >>> Article . ... objects . filter ( publications__title__startswith = "Science" ) . count () 2 >>> Article . objects . filter ( publications__title__startswith = "Science" ) . distinct () . ... ... 、複数のフィルタを連結することが可能です。たとえば、次のように書くことができます。 >>> Entry . objects . filter ( headline__startswith = "What" ) . exclude ( ... pub_date__gte = datetime . date . today () ... ) . filter ( pub_date__gte = datetime . date ( 2 ... に独立した QuerySet が作られるため、保存したり何度も再利用したりできます。 例: >>> q1 = Entry . objects . filter ( headline__startswith = "What" ) >>> q2 = q1 . exclude ( pub_date__gte = datetime . date . today ()) >>> q3 = q1 . filter ( pub_date__gte = date ... 価される までは、Django は実際にはクエリを実行しません。次の例を見てください。 >>> q = Entry . objects . filter ( headline__startswith = "What" ) >>> q = q . filter ( pub_date__lte = datetime . date . today ()) >>> q = q . exclude ( body_text__icontains = " ... ... 、複数のフィルタを連結することが可能です。たとえば、次のように書くことができます。 >>> Entry . objects . filter ( headline__startswith = "What" ) . exclude ( ... pub_date__gte = datetime . date . today () ... ) . filter ( pub_date__gte = datetime . date ( 2 ... に独立した QuerySet が作られるため、保存したり何度も再利用したりできます。 例: >>> q1 = Entry . objects . filter ( headline__startswith = "What" ) >>> q2 = q1 . exclude ( pub_date__gte = datetime . date . today ()) >>> q3 = q1 . filter ( pub_date__gte = date ... 価される までは、Django は実際にはクエリを実行しません。次の例を見てください。 >>> q = Entry . objects . filter ( headline__startswith = "What" ) >>> q = q . filter ( pub_date__lte = datetime . date . today ()) >>> q = q . exclude ( body_text__icontains = " ... ... . objects . get ( place__pk = 1 ) <Restaurant: Demon Dogs the restaurant> >>> Restaurant . objects . filter ( place__name__startswith = "Demon" ) <QuerySet [<Restaurant: Demon Dogs the restaurant>]> >>> Restaurant . objects . exclude ( place__address__cont ... lace . objects . get ( restaurant = r ) <Place: Demon Dogs the place> >>> Place . objects . get ( restaurant__place__name__startswith = "Demon" ) <Place: Demon Dogs the place> 場所を削除した場合、そのレストランは削除されます ( OneToOneField が on_delete に ... QuerySet [<Waiter: Joe the waiter at Demon Dogs the restaurant>]> >>> Waiter . objects . filter ( restaurant__place__name__startswith = "Demon" ) <QuerySet [<Waiter: Joe the waiter at Demon Dogs the restaurant>]> 前のトピックへ 多対一 (many-to-one) 関係 次 ... ... . objects . get ( place__pk = 1 ) <Restaurant: Demon Dogs the restaurant> >>> Restaurant . objects . filter ( place__name__startswith = "Demon" ) <QuerySet [<Restaurant: Demon Dogs the restaurant>]> >>> Restaurant . objects . exclude ( place__address__cont ... lace . objects . get ( restaurant = r ) <Place: Demon Dogs the place> >>> Place . objects . get ( restaurant__place__name__startswith = "Demon" ) <Place: Demon Dogs the place> 場所を削除した場合、そのレストランは削除されます ( OneToOneField が on_delete に ... QuerySet [<Waiter: Joe the waiter at Demon Dogs the restaurant>]> >>> Waiter . objects . filter ( restaurant__place__name__startswith = "Demon" ) <QuerySet [<Waiter: Joe the waiter at Demon Dogs the restaurant>]> 前のトピックへ 多対一 (many-to-one) 関係 次 ... ... jango.contrib.auth import get_user_model User = get_user_model () # Unsalted MD5/SHA1: User . objects . filter ( password__startswith = "md5$$" ) User . objects . filter ( password__startswith = "sha1$$" ) # Salted MD5/SHA1: User . objects . filter ( passw ... ord__startswith = "md5$" ) . exclude ( password__startswith = "md5$$" ) User . objects . filter ( password__startswith = "sha1$" ) . exclu ... de ( password__startswith = "sha1$$" ) # Crypt hasher: User . objects . filter ( password__startswith = "crypt$$" ) from django.db.models import Cha ... ... jango.contrib.auth import get_user_model User = get_user_model () # Unsalted MD5/SHA1: User . objects . filter ( password__startswith = "md5$$" ) User . objects . filter ( password__startswith = "sha1$$" ) # Salted MD5/SHA1: User . objects . filter ( passw ... ord__startswith = "md5$" ) . exclude ( password__startswith = "md5$$" ) User . objects . filter ( password__startswith = "sha1$" ) . exclu ... de ( password__startswith = "sha1$$" ) # Crypt hasher: User . objects . filter ( password__startswith = "crypt$$" ) from django.db.models import Cha ... 2026年10月08日