... ラス化できる列挙型があります: from django.utils.translation import gettext_lazy as _ class Student ( models . Model ): class YearInSchool ( models . TextChoices ): FRESHMAN = "FR" , _ ( "Freshman" ) SOPHOMORE = "SO" , _ ( "Sophomore" ) JUNIOR = "JR" , _ ( "Jun ... "SR" , _ ( "Senior" ) GRADUATE = "GR" , _ ( "Graduate" ) year_in_school = models . CharField ( max_length = 2 , choices = YearInSchool , default = YearInSchool . FRESHMAN , ) def is_upperclass ( self ): return self . year_in_school in { self . YearInSchool ... . JUNIOR , self . YearInSchool . SENIOR , } これらはPythonの標準ライブラリの enum と似たような動作をしますが、若干の変更が加えられています: 列挙型のメンバ ... ... ラス化できる列挙型があります: from django.utils.translation import gettext_lazy as _ class Student ( models . Model ): class YearInSchool ( models . TextChoices ): FRESHMAN = "FR" , _ ( "Freshman" ) SOPHOMORE = "SO" , _ ( "Sophomore" ) JUNIOR = "JR" , _ ( "Jun ... "SR" , _ ( "Senior" ) GRADUATE = "GR" , _ ( "Graduate" ) year_in_school = models . CharField ( max_length = 2 , choices = YearInSchool , default = YearInSchool . FRESHMAN , ) def is_upperclass ( self ): return self . year_in_school in { self . YearInSchool ... . JUNIOR , self . YearInSchool . SENIOR , } これらはPythonの標準ライブラリの enum と似たような動作をしますが、若干の変更が加えられています: 列挙型のメンバ ... 2026年10月08日