... 、明示的に正しいデータベース型にキャストされない限り、不正な型に変換される可能性があります: >>> from django.db.models import DateTimeField >>> from django.db.models.functions import Cast , Coalesce >>> from django.utils import timezone >>> now = timezone . now ... () >>> Coalesce ( "updated" , Cast ( now , DateTimeField ())) Collate class Collate ( expression , collation ) [ソース] クエリに使用する式と照合順序名 (collation name) を指定します ... するとデータベースエラーになります。 使用例: class Blog ( models . Model ): body = models . TextField () modified = models . DateTimeField ( auto_now = True ) class Comment ( models . Model ): body = models . TextField () modified = models . DateTimeField ( aut ... ... ogentry>, <django.db.models.fields.AutoField: id>, <django.db.models.fields.CharField: password>, <django.db.models.fields.DateTimeField: last_login>, <django.db.models.fields.BooleanField: is_superuser>, <django.db.models.fields.CharField: username>, <django ... ango.db.models.fields.BooleanField: is_staff>, <django.db.models.fields.BooleanField: is_active>, <django.db.models.fields.DateTimeField: date_joined>, <django.db.models.fields.related.ManyToManyField: groups>, <django.db.models.fields.related.ManyToManyField ... ogentry>, <django.db.models.fields.AutoField: id>, <django.db.models.fields.CharField: password>, <django.db.models.fields.DateTimeField: last_login>, <django.db.models.fields.BooleanField: is_superuser>, <django.db.models.fields.CharField: username>, <django ... ... ような、データベースに直接アクセスできる人のために、フィールドをドキュメント化するのに便利です。例えば: pub_date = models . DateTimeField ( db_comment = "Date and time when the article was published" , ) db_default Field. db_default データベースによって計算され ... るこのフィールドのデフォルト値。これはリテラル値でも、 Now のようなデータベース関数でも構いません: created = models . DateTimeField ( db_default = Now ()) リテラルやデータベース関数から構成する限り、より複雑な式を使用できます: month_due = models . DateFi ... い。なぜなら unique がインデックスの作成を意味するからです。 unique_for_date Field. unique_for_date これを DateField または DateTimeField の名前に設定すると、このフィールドが日付フィールドの値に対して一意であることを要求します。 例えば、 title フィールドに uni ... ... med in UTC. This limitation was lifted in Django 1.6. Use QuerySet.datetimes() to perform time zone aware aggregation on a DateTimeField . Support for savepoints in SQLite Django 1.6 adds support for savepoints in SQLite, with some limitations . BinaryField m ... used to return a list of datetime . QuerySet.datetimes() returns a list of datetime . QuerySet.dates() no longer usable on DateTimeField QuerySet.dates() raises an error if it's used on DateTimeField when time zone support is active. Use QuerySet.datetimes() ... uires time zone definitions The date_hierarchy feature of the admin now relies on QuerySet.datetimes() when it's used on a DateTimeField . This requires time zone definitions in the database when USE_TZ is True . Learn more . date_list in generic views requir ... ... ent reverse relationships in multi-table inheritance ( #27407 ). Fixed a QuerySet.update() crash on SQLite when updating a DateTimeField with an F() expression and a timedelta ( #27544 ). Prevented LocaleMiddleware from redirecting on URLs that should return ... ... 31271 ). Fixed a regression in Django 3.0.3 that caused misplacing parameters of SQL queries when subtracting DateField or DateTimeField expressions on MySQL ( #31312 ). Fixed a regression in Django 3.0 that didn't include subqueries spanning multivalued rela ... ... port models class Question ( models . Model ): question_text = models . CharField ( max_length = 200 ) pub_date = models . DateTimeField ( "date published" ) class Choice ( models . Model ): question = models . ForeignKey ( Question , on_delete = models . CAS ... 表現しています。 各フィールドは Field クラスのインスタンスとして表現されています。例えば、 CharField は文字のフィールドで、 DateTimeField は日時フィールドです。こうしたクラスは、各フィールドにどのようなデータ型を記憶させるかを Django に教えます。 Field インスタ ... 集してみましょう: 以下の点に注意してください: フォームは Question モデルから自動的に生成されます。 モデルのフィールドの型 ( DateTimeField 、 CharField など) はそれぞれ異なる HTML 入力ウィジェットと対応しています。各種のフィールドは、自分自身を Django admin サイ ... ... lass Reservation ( models . Model ): room = models . ForeignKey ( "Room" , on_delete = models . CASCADE ) start = models . DateTimeField () end = models . DateTimeField () cancelled = models . BooleanField ( default = False ) class Meta : constraints = [ Excl ... ... can be used by widgets to access model instances. See リレーションシップの選択肢をイテレートする for details. django.forms.DateTimeField now accepts dates in a subset of ISO 8601 datetime formats, including optional timezone, e.g. 2019-10-10T06:47 , 2019-10-1 ... ill always be retained if provided, with timezone-aware datetimes being returned even when USE_TZ is False . Additionally, DateTimeField now uses DATE_INPUT_FORMATS in addition to DATETIME_INPUT_FORMATS when converting a field input to a datetime value. Multi ... SQL to reset sequences on SQLite. モデル The new ExtractIsoWeekDay function extracts ISO-8601 week days from DateField and DateTimeField , and the new iso_week_day lookup allows querying by an ISO-8601 day of week. QuerySet.explain() now supports: TREE format ... ... ードを見つけやすくするために、Django は naive な datetime をデータベースに保存しようとすると警告を出します: RuntimeWarning: DateTimeField ModelName.field_name received a naive datetime (2012-01-01 00:00:00) while time zone support is active. 開発中、以下を設定 ... 例外として発生するように変更し、トラックバックを得ることができます: import warnings warnings . filterwarnings ( "error" , r "DateTimeField .* received a naive datetime" , RuntimeWarning , r "django\.db\.models\.fields" , ) フィクスチャ (fixture) aware な日時をシ ... オフセットが含まれます: "2011-09-01T13:20:30+03:00" しかし、naive な日付の場合はそうではありません: "2011-09-01T13:20:30" DateTimeField を使ったモデルに対しては、この違いにより、タイムゾーンサポートのありとなし両方に対して動作するフィクスチャを記述することが ... 2026年10月08日