{ "info": { "author": "HZDG, Lubos Matl", "author_email": "matllubos@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.10", "Framework :: Django :: 1.11", "Framework :: Django :: 1.8", "Framework :: Django :: 2.0", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP" ], "description": "This package lets you use real Python (PEP435_-style) enums with Django.\n\n.. image:: https://travis-ci.org/druids/django-choice-enumfields.svg?branch=master\n :target: https://travis-ci.org/druids/django-choice-enumfields\n\n\nInstallation\n------------\n\n1. ``pip install django-choice-enumfields``\n\n\nIncluded Tools\n--------------\n\n\nEnumField, NumEnumField\n```````````````````````\n\n.. code-block:: python\n\n from enumfields import EnumField\n from enumfields import ChoiceEnum # Uses Ethan Furman's \"enum34\" backport\n\n class Color(ChoiceEnum):\n RED = 'r'\n GREEN = 'g'\n BLUE = 'b'\n\n class MyModel(models.Model):\n\n color = EnumField(Color, max_length=1)\n\nElsewhere:\n\n.. code-block:: python\n\n m = MyModel.objects.filter(color=Color.RED)\n\n``NumEnumField`` works identically, but the underlying storage mechanism is\nan ``IntegerField`` instead of a ``CharField``.\n\n\nEnumSubField, NumEnumSubField\n`````````````````````````````\n\n.. code-block:: python\n\n from enumfields import EnumField, EnumSubField\n from enumfields import ChoiceEnum\n\n class Color(ChoiceEnum):\n RED = 'r'\n GREEN = 'g'\n BLUE = 'b'\n\n class ColorType(ChoiceEnum):\n LIGHT = Choice('l', 'light', parents=(Color.RED, Color.BLUE))\n DARK = Choice('d', 'dark', parents=(Color.RED, Color.GREEN))\n TRANSPARENT = Choice('t', 'transparent', parents=(Color.GREEN))\n\n class MyModel(models.Model):\n\n color = EnumField(Color, max_length=1)\n color_type = EnumSubField('color', ColorType, max_length=1)\n\n MyModel(color=Color.RED, color_type=ColorType.LIGHT).full_clean() # OK\n MyModel(color=Color.RED, color_type=ColorType.TRANSPARENT).full_clean() # Raise ValidationError\n\n``EnumSubField`` automatically validates if parents requirement is satisfied.\n\nWith ``EnumSubField``, ``EnumField``, ``NumEnumSubField`` and ``NumEnumField``\ncomes validation of initial and allowed transitions between choices out of the box.\n\n.. code-block:: python\n\n from enumfields import EnumField\n from enumfields import Choice, ChoiceEnum\n\n class StateFlow(ChoiceEnum):\n START = Choice('s', 'start', next={'PROCESSING'})\n PROCESSING = Choice('p', 'processing', next={'END'}, initial=False)\n END = Choice('e', 'end', next=set(), initial=False)\n\n class MyModel(models.Model):\n\n state = EnumField(StateFlow, max_length=1)\n\n MyModel(state=StateFlow.START).full_clean() # OK\n\n # Raise ValidationError because PROCESSING is not in initial states\n MyModel(state=StateFlow.PROCESSING).full_clean()\n\n model = MyModel.objects.create(StateFlow.START)\n model.state = StateFlow.END\n # Raise ValidationError because END is not next state after START\n model.full_clean()\n\n model.state = StateFlow.PROCESSING\n model.full_clean() # OK\n\n\nUsage in Forms\n~~~~~~~~~~~~~~\n\nCall the ``formfield`` method to use an ``EnumField`` directly in a ``Form``.\n\n.. code-block:: python\n\n class MyForm(forms.Form):\n\n color = EnumField(Color, max_length=1).formfield()\n\nChoiceEnum\n``````````\n\nNormally, you just use normal PEP435_-style enums, however, django-choice-enumfields\nalso encludes its own version of ChoiceEnum with a few extra bells and whistles.\nNamely, the smart definition of labels which are used, for example, in admin\ndropdowns. By default, it will create labels by title-casing your constant\nnames. You can provide custom labels with using Choice to define enum item.\n\n.. code-block:: python\n\n from enumfields import EnumField, ChoiceEnum, Choice # Our own Enum class\n\n class Color(ChoiceEnum):\n RED = Choice('r', 'A custom label')\n GREEN = 'g'\n BLUE = 'b'\n\n class MyModel(models.Model):\n color = EnumField(Color, max_length=1)\n\n assert Color.GREEN.label == 'Green'\n assert Color.RED.label == 'A custom label'\n\n\n.. _PEP435: http://www.python.org/dev/peps/pep-0435/\n\n\nEnumFieldListFilter\n```````````````````\n\n``enumfields.admin.EnumFieldListFilter`` is provided to allow using enums in\n``list_filter``.\n\n\n.. code-block:: python\n\n from enumfields.admin import EnumFieldListFilter\n\n class MyModelAdmin(admin.ModelAdmin):\n list_filter = [('color', EnumFieldListFilter)]", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/druids/django-choice-enumfields", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-choice-enumfields", "package_url": "https://pypi.org/project/django-choice-enumfields/", "platform": "", "project_url": "https://pypi.org/project/django-choice-enumfields/", "project_urls": { "Homepage": "https://github.com/druids/django-choice-enumfields" }, "release_url": "https://pypi.org/project/django-choice-enumfields/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "Real Python Enums for Django.", "version": "1.0.3" }, "last_serial": 5655983, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "0534fbf941ac0e83323daf60e6b7af47", "sha256": "1ffa2e2df1f69961d9acb4e48125be3740ff4a5a9c8cb44a3d55c428580a1ee6" }, "downloads": -1, "filename": "django-choice-enumfields-1.0.0.tar.gz", "has_sig": false, "md5_digest": "0534fbf941ac0e83323daf60e6b7af47", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8194, "upload_time": "2019-03-12T11:57:35", "url": "https://files.pythonhosted.org/packages/e8/c3/80c65d8dc9fbcbbaf73c69519e24063183392096815c8ceabfaec88af217/django-choice-enumfields-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "02f9e38a7416414dbf85efc3880abd07", "sha256": "888ac76c64c6498f23c99c1de3e738077bed309a36e72ebc25006ff448006d44" }, "downloads": -1, "filename": "django-choice-enumfields-1.0.1.tar.gz", "has_sig": false, "md5_digest": "02f9e38a7416414dbf85efc3880abd07", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8222, "upload_time": "2019-03-13T21:20:29", "url": "https://files.pythonhosted.org/packages/29/7e/23f415ab44067e88dab5d5549799731c1c510085b0cfc696d7033dc27ee1/django-choice-enumfields-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "0c9fb079ddd159ea42d1bb1ac2b9df89", "sha256": "a6b0206654942fd0010bb469b2eafb9bfe732e205967f40459ea0e708dcd7de1" }, "downloads": -1, "filename": "django-choice-enumfields-1.0.2.tar.gz", "has_sig": false, "md5_digest": "0c9fb079ddd159ea42d1bb1ac2b9df89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8861, "upload_time": "2019-05-27T21:05:45", "url": "https://files.pythonhosted.org/packages/79/09/c769343b1573013c0d0c992ca90ee7644c6e9ccc6bc51da0ec45159c6aca/django-choice-enumfields-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "147b4ee5ab57a52143b13a3c0708300f", "sha256": "0231ba0a9462613a6aa5790e9ab1dc46f4746b146064a7a386b023ce6acbc0d1" }, "downloads": -1, "filename": "django-choice-enumfields-1.0.3.tar.gz", "has_sig": false, "md5_digest": "147b4ee5ab57a52143b13a3c0708300f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8960, "upload_time": "2019-06-09T19:37:44", "url": "https://files.pythonhosted.org/packages/fa/3d/94ddce62ac8408c5525d6909340e437d43cb9f11ad557ba53e98a5dd5774/django-choice-enumfields-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "147b4ee5ab57a52143b13a3c0708300f", "sha256": "0231ba0a9462613a6aa5790e9ab1dc46f4746b146064a7a386b023ce6acbc0d1" }, "downloads": -1, "filename": "django-choice-enumfields-1.0.3.tar.gz", "has_sig": false, "md5_digest": "147b4ee5ab57a52143b13a3c0708300f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8960, "upload_time": "2019-06-09T19:37:44", "url": "https://files.pythonhosted.org/packages/fa/3d/94ddce62ac8408c5525d6909340e437d43cb9f11ad557ba53e98a5dd5774/django-choice-enumfields-1.0.3.tar.gz" } ] }