... E のサブ言語を利用できるように Django 3.0 で追加されたシステムチェックの設定を緩めました ( #31141 )。 テンプレートで列挙型 TextChoices 、 IntegerChoices 、そして Choices が使えるようになりました ( #31154 )。 名前付きグループが非文字列の値しか含まない場合でも ... ... ng to first annotate and then filter against the annotation. Enumerations for model field choices Custom enumeration types TextChoices , IntegerChoices , and Choices are now available as a way to define Field.choices . TextChoices and IntegerChoices types a ... ... 、 .choices 属性にアクセスして、期待される形式で値を提供する必要がありました: from django.db import models Medal = models . TextChoices ( "Medal" , "GOLD SILVER BRONZE" ) SPORT_CHOICES = [ ( "Martial Arts" , [( "judo" , "Judo" ), ( "karate" , "Karate" )]), ( ... ようになり、 列挙型 を直接展開することで、 .choices の使用が不要になりました。 from django.db import models Medal = models . TextChoices ( "Medal" , "GOLD SILVER BRONZE" ) SPORT_CHOICES = { # Using a mapping instead of a list of 2-tuples. "Martial Arts" : { " ... ... TION_DOWN : "Down" , } Alternatively, consider using 列挙型 : class MyModel ( models . Model ): class Direction ( models . TextChoices ): UP = "U" , "Up" DOWN = "D" , "Down" Use of django.conf.settings Modules should not in general use settings stored in dj ... ... ます: from django.utils.translation import gettext_lazy as _ class Student ( models . Model ): class YearInSchool ( models . TextChoices ): FRESHMAN = "FR" , _ ( "Freshman" ) SOPHOMORE = "SO" , _ ( "Sophomore" ) JUNIOR = "JR" , _ ( "Junior" ) SENIOR = "SR" , ... 自動設定させることができます(アンダースコアをスペースに置き換え、タイトルケースを使用します): >>> class Vehicle ( models . TextChoices ): ... CAR = "C" ... TRUCK = "T" ... JET_SKI = "J" ... >>> Vehicle . JET_SKI . label 'Jet Ski' 列挙値が整数である必要がある ... Enum Functional API を利用することもできます。この場合、ラベルは上記のように自動的に生成されます: >>> MedalType = models . TextChoices ( "MedalType" , "GOLD SILVER BRONZE" ) >>> MedalType . choices [('GOLD', 'Gold'), ('SILVER', 'Silver'), ('BRONZE', 'Bronze ... ... e converted to str or bytes using os.fspath() LazyObject instances which wrap a serializable value Enumeration types (e.g. TextChoices or IntegerChoices ) instances 任意の Django フィールド 任意の関数またはメソッドへのリファレンス (例: datetime.datetime.tod ... ... hoices を簡潔に定義することもできます。 from django.db import models class Runner ( models . Model ): MedalType = models . TextChoices ( "MedalType" , "GOLD SILVER BRONZE" ) name = models . CharField ( max_length = 60 ) medal = models . CharField ( blank = ... 2026年10月08日