Package: django-richenum
django-richenumAboutA Django extension of richenum for Python. If you’re unfamiliar with richenums, please read up on them (seeRelated Packages) before using django-richenum.Model FieldsIndexEnumFieldStore ints in DB, but expose OrderedRichEnumValues in Python.CanonicalNameEnumFieldStore varchar in DB, but expose RichEnumValues in Python.
We recommend that you use IndexEnumField for storage and query efficiency.LaxIndexEnumFieldLike IndexEnumField, but also allows casting to and from canonical names.
Mainly used to help migrate existing code that uses strings as database values.Form FieldsCanonicalEnumFieldUses the RichEnum/OrderedRichEnum canonical_name as form field values.IndexEnumFieldUses the OrderedRichEnum index as form field values.Django AdminRichEnumFieldListFilterEnables filtering by RichEnum model fields in the Django admin UILinksGitHub: django-richenumPyPi: django-richenumInstallation$pipinstalldjango-richenumExample UsageIndexEnumField>>>fromrichenumimportOrderedRichEnum,OrderedRichEnumValue>>>classMyOrderedRichEnum(OrderedRichEnum):...FOO=OrderedRichEnumValue(index=1,canonical_name="foo",display_name="Foo")...BAR=OrderedRichEnumValue(index=2,canonical_name="bar",display_name="Bar")...>>>fromdjango.dbimportmodels>>>fromdjango_richenum.modelsimportIndexEnumField>>>classMyModel(models.Model):...my_enum=IndexEnumField(MyOrderedRichEnum,default=MyOrderedRichEnum.FOO)...>>>m=MyModel.objects.create(my_enum=MyOrderedRichEnum.BAR)>>>m.save()>>>m.my_enumOrderedRichEnumValue-idx:2canonical_name:'bar'display_name:'Bar'>>>MyModel.objects.filter(my_enum=MyOrderedRichEnum.BAR)CanonicalNameEnumField>>>fromrichenumimportRichEnum,RichEnumValue>>>classMyRichEnum(RichEnum):...FOO=RichEnumValue(canonical_name="foo",display_name="Foo")...BAR=RichEnumValue(canonical_name="bar",display_name="Bar")...>>>fromdjango.dbimportmodels>>>fromdjango_richenum.modelsimportCanonicalNameEnumField>>>classMyModel(models.Model):...my_enum=CanonicalNameEnumField(MyRichEnum,default=MyRichEnum.FOO)...>>>m=MyModel.objects.create(my_enum=MyRichEnum.BAR)>>>m.save()>>>m.my_enumRichEnumValue-canonical_name:'bar'display_name:'Bar'>>>MyModel.objects.filter(my_enum=MyRichEnum.BAR)RichEnumFieldListFilter>>>fromdjango_richenum.adminimportregister_admin_filters>>>register_admin_filters()Related PackagesrichenumPackage implementing RichEnum and OrderedRichEnum that django-richenum depends on.GitHub: richenumPyPi: richenumNotesIf you’re using Django 1.7+, you’ll need to use the@deconstructibledecorator for yourRichEnumValueandOrderedRichEnumValueclasses so Django’s migration framework knows how to serialize yourRichEnumValueandOrderedRichEnumValue.>>>fromdjango.utils.deconstructimportdeconstructible>>>fromrichenumimportRichEnumValue,OrderedRichEnumValue>>>@deconstructible...classCustomRichEnumValue(RichEnumValue):...pass...>>>@deconstructible...classCustomOrderedRichEnumValue(OrderedRichEnumValue):...pass...ContributingFork the repo fromGitHub.Make your changes.Add unittests for your changes.Runpep8,pyflakes, andpylintto make sure your changes follow the Python style guide and doesn’t have any errors.Add yourself to the AUTHORS file (in alphabetical order).Send a pull request from your fork to the main repo.Changelog4.1.0 (2023-12-12)Support for Django 4.2Support for Python 3.11Remove support for Django 2.2, 3.0, 3.1Remove support for Python 3.7Require MySQL 8 and Postgres 123.7.0 (2019-09-05)Support for Django 2.33.6.0 (2019-07-09)Support for Django 2.2Support for Python 3.7Remove support for Django 2.03.5.0 (2018-09-10)Fix [deprecation of context param for Field.from_db_value](https://code.djangoproject.com/ticket/28370)Support for Django 2.1Switch tests suite to use pytestRemove pylint-django plugin, no longer needed3.4.0 (2018-02-10)Drop support for old Django versions3.3.0 (2018-01-21)removed Python 3.4add support for Python 3.6add support for Django 2.0Properly mark raw strings (used as regex)3.2.0 (2016-08-22)Python 3.4 & 3.5 support3.1.0 (2015-08-02)Django 1.10 support3.0.1 (2015-07-13)Prepare for python 3 support2.4.1 (2015-05-04)replace mysql client library (for tests)stop using lambdas2.3.0 (2015-05-04)Support Django 1.82.2.0 (2015-03-11)Support ModelForms for non-SQLite DB backends2.1.0 (2014-11-01)Support migration in Django 1.72.0.0 (2014-09-04)Support Django 1.7, drop support for Python 2.6.1.2.2 (2014-08-02)Support Django 1.31.2.1 (2014-06-02)Remove uses of BaseException.message.1.2.0 (2013-12-03)Add enum-aware versions of TypedMultipleChoiceField.1.1.0 (2013-12-03)Fix form fields to support Django 1.6 (while maintaining
compatibility with 1.4 and 1.5).1.0.2 (2013-11-05)Make EnumField.run_validators a no-op.
This stops some warnings from type comparison, and it doesn’t seem
useful in an EnumField context.1.0.1 (2013-09-10)Support South.1.0.0 (2013-08-16)Initial public release.Developed and maintained byHearsay Social, Inc..ContributorsAdam DePueAkshay ShahDale HuiRobert MacCloyBen LopatinAsher FoaKrisztian Csizmazia