的Django 1.10,PY 3.5Django的檢測並不需要改變
這裏是我的枚舉類類:
@deconstructible
class EnumType(object):
@classmethod
def choices(cls):
attrs = [i for i in cls.__dict__.keys() if i[:1] != '_' and i.isupper()]
return tuple((cls.__dict__[attr], cls.__dict__[attr]) for attr in attrs)
def __eq__(self, other):
return self.choices() == other.choices()
這裏的類的實例:
class TransmissionType(EnumType):
TRANSMISSION_PROGRAM = 'TRANSMISSION_PROGRAM'
INFO_PROGRAM = 'INFO_PROGRAM'
SPORT_PROGRAM = 'SPORT_PROGRAM'
下面是我如何使用它在一個模型上:
type = models.TextField(choices=TransmissionType.choices(), db_index=True, default=None)
I th
operations = [
migrations.AlterField(
model_name='transmission',
name='type',
field=models.TextField(choices=[('TRANSMISSION_PROGRAM', 'TRANSMISSION_PROGRAM'), ('INFO_PROGRAM', 'INFO_PROGRAM'), ('SPORT_PROGRAM', 'SPORT_PROGRAM')], db_index=True, default=None),
),
]
EDIT1:墨水我的權利根據當前django deconstruct docs但顯然makemigration腳本仍然創建每次遷移作出這樣一切 預期行爲 - 當類成員不改變產生migaration不應包括AlterField
什麼是你期待? –
我剛剛對我的期望進行了編輯 – jnowak
在您做出此更改之前,模型的外觀如何? – e4c5