... ut_field ) [ソース] ¶ 式 expression の結果の型を output_field の型に強制的に変更します。 使用例: >>> from django.db.models import FloatField >>> from django.db.models.functions import Cast >>> Author . objects . create ( age = 25 , name = "Margaret Smi ... 混在するとデータベースエラーになります。 使用例: >>> # Get a screen name from least to most public >>> from django.db.models import Sum >>> from django.db.models.functions import Coalesce >>> Author . objects . create ( name = "Margaret Smith" , goes_by ... の値は、明示的に正しいデータベース型にキャストされない限り、不正な型に変換される可能性があります: >>> from django.db.models import DateTimeField >>> from django.db.models.functions import Cast , Coalesce >>> from django.utils import timezone >>> now = t ... ... ut_field ) [ソース] ¶ 式 expression の結果の型を output_field の型に強制的に変更します。 使用例: >>> from django.db.models import FloatField >>> from django.db.models.functions import Cast >>> Author . objects . create ( age = 25 , name = "Margaret Smi ... 混在するとデータベースエラーになります。 使用例: >>> # Get a screen name from least to most public >>> from django.db.models import Sum >>> from django.db.models.functions import Coalesce >>> Author . objects . create ( name = "Margaret Smith" , goes_by ... の値は、明示的に正しいデータベース型にキャストされない限り、不正な型に変換される可能性があります: >>> from django.db.models import DateTimeField >>> from django.db.models.functions import Cast , Coalesce >>> from django.utils import timezone >>> now = t ... ... {**x, **y} ) or sequences ( [*a, *b] ). This improves performance, readability, and maintainability while reducing errors. Imports ¶ Use isort to automate import sorting using the guidelines below. Quick start: / $ python -m pip install "isort >= 7 ... ort recursively from your current directory, modifying any files that don't conform to the guidelines. If you need to have imports out of order (to avoid a circular import, for example) use a comment like this: import module # isort:skip Put imports in ... omponents, local Django component, try/excepts. Sort lines in each group alphabetically by the full module name. Place all import module statements before from module import objects in each section. Use absolute imports for other Django components and ... ... {**x, **y} ) or sequences ( [*a, *b] ). This improves performance, readability, and maintainability while reducing errors. Imports ¶ Use isort to automate import sorting using the guidelines below. Quick start: / $ python -m pip install "isort >= 7 ... ort recursively from your current directory, modifying any files that don't conform to the guidelines. If you need to have imports out of order (to avoid a circular import, for example) use a comment like this: import module # isort:skip Put imports in ... omponents, local Django component, try/excepts. Sort lines in each group alphabetically by the full module name. Place all import module statements before from module import objects in each section. Use absolute imports for other Django components and ... ... えるとわかりやすいでしょう。次のようなフォームがあるとしましょう: >>> from django import forms >>> class ArticleForm ( forms . Form ): ... title = forms . CharField () ... pub_date = forms . DateField () ... ユー ... 成できるようにしたいと思うかもしれません。 ArticleForm からフォームセットを作るには、次のようにします: >>> from django.forms import formset_factory >>> ArticleFormSet = formset_factory ( ArticleForm ) これで ArticleFormSet という名前のフォームセットクラス ... セットが初期データから生成するフォームに加え、追加で表示するフォームの数を指定することを意味します。例を見てみましょう: >>> import datetime >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset ... ... のため、グローバル名前空間に _() をインストールすると、干渉して問題を引き起こします。 gettext() を _() という名前で明示的に import すれば、この問題を回避できます。 _ として別名をつけられる関数は? ( makemessages で使われる) xgettext が動作する方法のせいで ... 、単一の文字列引数を持つ関数のみが _ として import できます。 gettext() gettext_lazy() この例では、 "Welcome to my site." というテキストが翻訳文字列としてマークされています: ... from django.http import HttpResponse from django.utils.translation import gettext as _ def my_view ( request ): output = _ ( "Welcome to my site." ... ... えるとわかりやすいでしょう。次のようなフォームがあるとしましょう: >>> from django import forms >>> class ArticleForm ( forms . Form ): ... title = forms . CharField () ... pub_date = forms . DateField () ... ユー ... 成できるようにしたいと思うかもしれません。 ArticleForm からフォームセットを作るには、次のようにします: >>> from django.forms import formset_factory >>> ArticleFormSet = formset_factory ( ArticleForm ) これで ArticleFormSet という名前のフォームセットクラス ... セットが初期データから生成するフォームに加え、追加で表示するフォームの数を指定することを意味します。例を見てみましょう: >>> import datetime >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset ... ... のため、グローバル名前空間に _() をインストールすると、干渉して問題を引き起こします。 gettext() を _() という名前で明示的に import すれば、この問題を回避できます。 _ として別名をつけられる関数は? ( makemessages で使われる) xgettext が動作する方法のせいで ... 、単一の文字列引数を持つ関数のみが _ として import できます。 gettext() gettext_lazy() この例では、 "Welcome to my site." というテキストが翻訳文字列としてマークされています: ... from django.http import HttpResponse from django.utils.translation import gettext as _ def my_view ( request ): output = _ ( "Welcome to my site." ... ... 注釈 このページの例のいくつかは、 myapp/models.py 内で下記の通り Article モデルが定義されていると仮定します: from django.db import models from django.urls import reverse class Article ( models . Model ): title = models . CharField ( max_length = 200 ) p ... d 属性を用いた月や日に変更できます。これは、すべてのサブクラスのビューに適用されます。 例 myapp/urls.py : from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path ( "arch ... ます。 ノート デフォルトの template_name_suffix は _archive_year です。 例 myapp/views.py : from django.views.generic.dates import YearArchiveView from myapp.models import Article class ArticleYearArchiveView ( YearArchiveView ): queryset = Article . ob ... ... 注釈 このページの例のいくつかは、 myapp/models.py 内で下記の通り Article モデルが定義されていると仮定します: from django.db import models from django.urls import reverse class Article ( models . Model ): title = models . CharField ( max_length = 200 ) p ... d 属性を用いた月や日に変更できます。これは、すべてのサブクラスのビューに適用されます。 例 myapp/urls.py : from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path ( "arch ... ます。 ノート デフォルトの template_name_suffix は _archive_year です。 例 myapp/views.py : from django.views.generic.dates import YearArchiveView from myapp.models import Article class ArticleYearArchiveView ( YearArchiveView ): queryset = Article . ob ... 2026年10月08日