... s() get_dated_queryset() get_paginator() head() http_method_not_allowed() paginate_queryset() render_to_response() setup() MonthArchiveView class MonthArchiveView 属性 (とオプションのアクセサ): allow_empty [ get_allow_empty() ] allow_future [ get_allo ... pe context_object_name [ get_context_object_name() ] date_field [ get_date_field() ] extra_context http_method_names model month [ get_month() ] month_format [ get_month_format() ] ordering [ get_ordering() ] paginate_by [ get_paginate_by() ] paginate ... ) ] メソッド as_view() dispatch() get() get_context_data() get_date_list() get_dated_items() get_dated_queryset() get_next_month() get_paginator() get_previous_month() head() http_method_not_allowed() paginate_queryset() render_to_response() setup() W ... ... h1 > {% for obj in object_list %} < p > {{ obj.title }} - {{ obj.pub_date | date :"F j, Y" }} </ p > {% endfor %} </ div > MonthArchiveView class MonthArchiveView [ソース] 与えられた月の中で有効な全オブジェクトを表示する、月次のアーカイブページです。 ... ic.list.MultipleObjectTemplateResponseMixin django.views.generic.base.TemplateResponseMixin django.views.generic.dates.BaseMonthArchiveView django.views.generic.dates.YearMixin django.views.generic.dates.MonthMixin django.views.generic.dates.BaseDateL ... queryset に従って、与えられた月にオブジェクトが利用可能な全ての日を、 datetime.datetime オブジェクトとして昇順で表します。 month : 与えられた月を表す date オブジェクト。 next_month : allow_empty と allow_future に従って、次の月の最初の日を表す date オ ... ... ジェクトを返します。この関数は allow_empty と allow_future の値によって None を返したり、 Http404 例外を発生させたりします。 MonthMixin class MonthMixin [ソース] 日付の「月」コンポーネントのパース情報を取得したり提供したりするために使用できるミックスイン ... 。 メソッドと属性 month_format strftime() フォーマットは月をパースするときに使われます。デフォルトでは '%b' です。 month オプション 月を表す文字列 ... 。デフォルトでは None に設定されています。これは月が他の方法で決定されることを意味します。 get_month_format () [ソース] 月をパースする際に使用する strftime() フォーマットを返します。デフォルトでは month_format を返します。 ... ... :30:01.000321+00:00 が渡されると、組み込みの lookup_name は下記の値を返します: "year": 2015 "iso_year": 2015 "quarter": 2 "month": 6 "day": 15 "week": 25 "week_day": 2 "iso_week_day": 1 "hour": 23 "minute": 30 "second": 1 Australia/Melbourne のような異 ... pression , tzinfo = None , ** extra ) [ソース] ISO-8601 の週番号を持つ年を返します。 lookup_name = 'iso_year' class ExtractMonth ( expression , tzinfo = None , ** extra ) [ソース] lookup_name = 'month' class ExtractDay ( expression , tzinfo = None , * ... ができます: >>> from datetime import UTC , datetime >>> from django.db.models.functions import ( ... ExtractDay , ... ExtractMonth , ... ExtractQuarter , ... ExtractWeek , ... ExtractIsoWeekDay , ... ExtractWeekDay , ... ExtractIsoYear , ... ExtractYear ... ... エリを修正して、 Client が私たちとどれくらいの期間、関係があるかに基づいて割引を得るには、ルックアップが使用できます: >>> a_month_ago = date . today () - timedelta ( days = 30 ) >>> a_year_ago = date . today () - timedelta ( days = 365 ) >>> # Get the ... discount = Case ( ... When ( registered_on__lte = a_year_ago , then = Value ( "10%" )), ... When ( registered_on__lte = a_month_ago , then = Value ( "5%" )), ... default = Value ( "0%" ), ... ) ... ) . values_list ( "name" , "discount" ) <QuerySet [( ... ます。たとえば、1ヶ月以上前に登録されたゴールドクライアントと1年以上前に登録されたプラチナクライアントを検索する場合: >>> a_month_ago = date . today () - timedelta ( days = 30 ) >>> a_year_ago = date . today () - timedelta ( days = 365 ) >>> Client . o ... ... ectorWidget ( forms . MultiWidget ): def __init__ ( self , attrs = None ): days = { day : day for day in range ( 1 , 32 )} months = { month : month for month in range ( 1 , 13 )} years = { year : year for year in [ 2018 , 2019 , 2020 ]} widgets = [ fo ... rms . Select ( attrs = attrs , choices = days ), forms . Select ( attrs = attrs , choices = months ), forms . Select ( attrs = attrs , choices = years ), ] super () . __init__ ( widgets , attrs ) def decompress ( self , ... value ): if isinstance ( value , date ): return [ value . day , value . month , value . year ] elif isinstance ( value , str ): year , month , day = value . split ( "-" ) return [ day , month , year ] ... ... /" , views . special_case_2003 ), path ( "articles/<int:year>/" , views . year_archive ), path ( "articles/<int:year>/<int:month>/" , views . month_archive ), path ( "articles/<int:year>/<int:month>/<slug:slug>/" , views . article_detail ), ] メモ: UR ... cles です。 リクエストの例: articles/2005/03/ へのリクエストはリストの 3 番目のエントリにマッチします。Django は関数 views.month_archive(request, year=2005, month=3) を呼び出します。 /articles/2003/ はリストの最初のパターンにマッチしますが、2番目のパタ ... les/2003/03/building-a-django-site/ は最後のパターンにマッチします。Django は関数 views.article_detail(request, year=2003, month=3, slug="building-a-django-site") を呼び出します。 パス コンバータ デフォルトでは、以下のパスコンバータが使用可能です: str ... ... の標準の名前付き補完構文によるプレースホルダを使えます。例えば: def my_view ( request , m , d ): output = _ ( "Today is %(month)s %(day)s ." ) % { "month" : m , "day" : d } return HttpResponse ( output ) このテクニックを使うと、言語ごとの翻訳でプレー ... , doesn't exist in 'msgid' 文脈マーカー Sometimes words have several meanings, such as "May" in English, which refers to a month name and to a verb. To enable translators to translate these words correctly in different contexts, you can use the django ... 現します)、これらそれぞれに対して翻訳者が異なる翻訳ができるようにします。 例: from django.utils.translation import pgettext month = pgettext ( "month name" , "May" ) もしくは: from django.db import models from django.utils.translation import pgettext_l ... ... om . import views urlpatterns = [ path ( "articles/<int:year>/" , views . year_archive ), path ( "articles/<int:year>/<int:month>/" , views . month_archive ), path ( "articles/<int:year>/<int:month>/<int:pk>/" , views . article_detail ), ] 上のコードは ... ユーザが "/articles/2005/05/39323/" という URL をリクエストすると、 Django は news.views.article_detail(request, year=2005, month=5, pk=39323) のような関数呼び出しを行います。 ビューの自作 各ビューには二つの役割があります: 一つはリクエストされたページの ... ... ld from DateField ( #27828 ). Fixed query expression date subtraction accuracy on PostgreSQL for differences larger than a month ( #27856 ). Fixed a GDALException raised by GDALClose on GDAL ≥ 2.0 ( #27479 ). ... 2026年10月08日