django-enumfield icon indicating copy to clipboard operation
django-enumfield copied to clipboard

Nested enum generates incorrect migration

Open wli opened this issue 9 years ago • 4 comments

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

wli avatar Dec 30 '15 02:12 wli

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!

andreif avatar Feb 10 '17 13:02 andreif

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 :)

hyusetiawan avatar Dec 29 '19 06:12 hyusetiawan

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.

antonagestam avatar Jan 02 '20 09:01 antonagestam

Any news on this?

cyberpion-yotam avatar Feb 03 '21 16:02 cyberpion-yotam