django-enumfield
django-enumfield copied to clipboard
Nested enum generates incorrect migration
This is using Django 1.9 with django-enumfield 1.3b2
class Hike(models.Model):
class ExposureType(enum.Enum):
UNKNOWN = 0
exposure_type = enum.EnumField(ExposureType, default=ExposureType.UNKNOWN)
generates
operations = [
migrations.AlterField(
model_name='hike',
name='exposure_type',
field=django_enumfield.db.fields.EnumField(default=0, enum=base.models.ExposureType),
),
It should instead generate enum=base.models.Hike.ExposureType
Interesting, I would normally keep all enums away from heavy modules, so one can import them without moving montains. We'll look if we can support this. Thanks for reporting the issue and sorry for late reply!
I am having the same issue as well, rather annoying @andreif I see your point about moving mountains, for smaller models though, it's more maintainable to have enum that only applies to this particular model. Makes it more neatly scoped :)
I think this bug should be accepted and fixed. The increased coherence of defining enums inside models should be encouraged.
I believe this might be fixed by replacing __name__
with __qualname__
, but that isn't available in Python 2.7 and early versions of 3.x. Now that Python 2.7 is EOL, we should probably discuss ending backwards compatibility for some of those versions anyway.
Any news on this?