django 1.10, py 3.5
Here's my Enum-like class:
@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()
Here's an example of the class:
class TransmissionType(EnumType):
TRANSMISSION_PROGRAM = 'TRANSMISSION_PROGRAM'
INFO_PROGRAM = 'INFO_PROGRAM'
SPORT_PROGRAM = 'SPORT_PROGRAM'
Here's how i use it on a model:
type = models.TextField(choices=TransmissionType.choices(), db_index=True, default=None)
I think I made everything right according to the current django deconstruct docs but apparently makemigration script still creates everytime migration like this:
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: expected behaviour - when class members does not change the generated migaration should not include AlterField