... False >>> page2 . has_previous () True >>> page2 . has_other_pages () True >>> page2 . next_page_number () Traceback (most recent call last): ... EmptyPage : That page contains no results >>> page2 . previous_page_number () 1 >>> page2 . start_index () ... his page 3 >>> page2 . end_index () # The 1-based index of the last item on this page 4 >>> p . page ( 0 ) Traceback (most recent call last): ... EmptyPage : That page number is less than 1 >>> p . page ( 3 ) Traceback (most recent call last): ... Empt ... list import count next previous last ListView Contact contact pages range index span href QuerySet objects Traceback most recent call EmptyPage クイック検索 Last update: 2026年10月09日 « previous | up | next » ... ... es are serialized to JSON, they must be JSON-serializable: >>> process_data . enqueue ( datetime . now ()) Traceback (most recent call last): ... TypeError : Object of type datetime is not JSON serializable Arguments must also be able to round-trip thr ... uble_dictionary . enqueue (( 1 , 2 , 3 )) >>> result . status FAILED >>> result . errors [ 0 ] . traceback Traceback (most recent call last): ... TypeError : unhashable type: 'list' The double_dictionary Task fails because after the JSON round-trip the ... shed executing, or has failed, ValueError is raised. >>> result . status RUNNING >>> result . return_value Traceback (most recent call last): ... ValueError : Task has not finished yet Errors ¶ If the Task doesn't succeed, and instead raises an excepti ... ... False >>> page2 . has_previous () True >>> page2 . has_other_pages () True >>> page2 . next_page_number () Traceback (most recent call last): ... EmptyPage : That page contains no results >>> page2 . previous_page_number () 1 >>> page2 . start_index () ... his page 3 >>> page2 . end_index () # The 1-based index of the last item on this page 4 >>> p . page ( 0 ) Traceback (most recent call last): ... EmptyPage : That page number is less than 1 >>> p . page ( 3 ) Traceback (most recent call last): ... Empt ... ... es are serialized to JSON, they must be JSON-serializable: >>> process_data . enqueue ( datetime . now ()) Traceback (most recent call last): ... TypeError : Object of type datetime is not JSON serializable Arguments must also be able to round-trip thr ... uble_dictionary . enqueue (( 1 , 2 , 3 )) >>> result . status FAILED >>> result . errors [ 0 ] . traceback Traceback (most recent call last): ... TypeError : unhashable type: 'list' The double_dictionary Task fails because after the JSON round-trip the ... shed executing, or has failed, ValueError is raised. >>> result . status RUNNING >>> result . return_value Traceback (most recent call last): ... ValueError : Task has not finished yet Errors ¶ If the Task doesn't succeed, and instead raises an excepti ... ... バグを見つけたとき ¶ 運よく、 polls のアプリケーションにはすぐに修正可能な小さなバグがありました。 Question.was_published_recently() のメソッドは Question が昨日以降に作成された場合に True を返すのですが(適切な動作)、 Question の pub_date が未来の日付 ... >>> future_question = Question ( pub_date = timezone . now () + datetime . timedelta ( days = 30 )) >>> # was it published recently? >>> future_question . was_published_recently () True 将来のことは「最近(recent)」ではないため、これは明らかに間違いで ... om django.utils import timezone from .models import Question class QuestionModelTests ( TestCase ): def test_was_published_recently_with_future_question ( self ): """ was_published_recently() returns False for questions whose pub_date is in the future. ... ... バグを見つけたとき ¶ 運よく、 polls のアプリケーションにはすぐに修正可能な小さなバグがありました。 Question.was_published_recently() のメソッドは Question が昨日以降に作成された場合に True を返すのですが(適切な動作)、 Question の pub_date が未来の日付 ... >>> future_question = Question ( pub_date = timezone . now () + datetime . timedelta ( days = 30 )) >>> # was it published recently? >>> future_question . was_published_recently () True 将来のことは「最近(recent)」ではないため、これは明らかに間違いで ... om django.utils import timezone from .models import Question class QuestionModelTests ( TestCase ): def test_was_published_recently_with_future_question ( self ): """ was_published_recently() returns False for questions whose pub_date is in the future. ... ... ilField () >>> f . clean ( "foo@example.com" ) 'foo@example.com' >>> f . clean ( "invalid email address" ) Traceback (most recent call last): ... ValidationError : ['Enter a valid email address.'] field のコアとなる引数 ¶ 各 Field クラスのコンストラクタ ... > from django import forms >>> f = forms . CharField () >>> f . clean ( "foo" ) 'foo' >>> f . clean ( "" ) Traceback (most recent call last): ... ValidationError : ['This field is required.'] >>> f . clean ( None ) Traceback (most recent call last): .. ... ーメッセージです: >>> from django import forms >>> generic = forms . CharField () >>> generic . clean ( "" ) Traceback (most recent call last): ... ValidationError : ['This field is required.'] そしてこれがカスタムエラーメッセージです: >>> name = forms . ... ... me import timedelta >>> from django.utils import timezone >>> one_day_ago = timezone . now () - timedelta ( days = 1 ) >>> recent_comments = Comment . objects . filter ( ... post = OuterRef ( "pk" ), ... created_at__gte = one_day_ago , ... ) >>> Post . ... objects . annotate ( recent_comment = Exists ( recent_comments )) PostgreSQLの場合、SQLは以下のようになります: SELECT "post" . "id" , "post" . "publis ... M "comment" U0 WHERE ( U0 . "created_at" >= YYYY - MM - DD HH : MM : SS AND U0 . "post_id" = "post" . "id" ) LIMIT 1 ) AS "recent_comment" FROM "post" Exists に単一のカラムの参照を強制する必要はありません。列は破棄され、真偽値の結果が返されるからです。 ... ... ilField () >>> f . clean ( "foo@example.com" ) 'foo@example.com' >>> f . clean ( "invalid email address" ) Traceback (most recent call last): ... ValidationError : ['Enter a valid email address.'] field のコアとなる引数 ¶ 各 Field クラスのコンストラクタ ... > from django import forms >>> f = forms . CharField () >>> f . clean ( "foo" ) 'foo' >>> f . clean ( "" ) Traceback (most recent call last): ... ValidationError : ['This field is required.'] >>> f . clean ( None ) Traceback (most recent call last): .. ... ーメッセージです: >>> from django import forms >>> generic = forms . CharField () >>> generic . clean ( "" ) Traceback (most recent call last): ... ValidationError : ['This field is required.'] そしてこれがカスタムエラーメッセージです: >>> name = forms . ... ... me import timedelta >>> from django.utils import timezone >>> one_day_ago = timezone . now () - timedelta ( days = 1 ) >>> recent_comments = Comment . objects . filter ( ... post = OuterRef ( "pk" ), ... created_at__gte = one_day_ago , ... ) >>> Post . ... objects . annotate ( recent_comment = Exists ( recent_comments )) PostgreSQLの場合、SQLは以下のようになります: SELECT "post" . "id" , "post" . "publis ... M "comment" U0 WHERE ( U0 . "created_at" >= YYYY - MM - DD HH : MM : SS AND U0 . "post_id" = "post" . "id" ) LIMIT 1 ) AS "recent_comment" FROM "post" Exists に単一のカラムの参照を強制する必要はありません。列は破棄され、真偽値の結果が返されるからです。 ... 2026年10月08日