{ "info": { "author": "Eerik Sven Puudist", "author_email": "eerik@herbfoods.eu", "bugtrack_url": null, "classifiers": [ "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Django Model Choices\n\nDjango Model Choices (DMC) provides a readable and DRY way to specify choices for Django models and forms. Although there are many similar projects available, Django Model Choices is willing to offer the most neat and DRY syntax.\n\n## Features\n\nA classic choices class in Django looks like this:\n\n```py\nclass CharityType(models.Model):\n SOCIAL = 'SOC'\n ENVIRONMENTAL = 'ENV'\n EDUCATIONAL = 'EDU'\n CHOICES = (\n (SOCIAL, 'Social'),\n (ENVIRONMENTAL, 'Environmental'),\n (EDUCATIONAL, 'Educational'),\n )\n```\n\nThis is far from being DRY and is also prone to typos and other mistakes. Using Django Model Choices you could do:\n\n```py\nfrom modelchoices import Choices\n\n\nclass CharityType(Choices):\n SOCIAL = ('SOC', 'Social')\n ENVIRONMENTAL = ('ENV', 'Environmental')\n EDUCATIONAL = ('EDU', 'Educational')\n```\n\nThe value of each choice must be a tuple containing a value for the database and a user readable value, which could also be translation object as in this example.\n\nThe `CHOICES` field will be generated magically by the metaclass, so you can use it in the model like this:\n\n```py\nclass Charity(models.Model):\n charity_type = models.CharField(max_length=1, choices=CharityType.CHOICES)\n```\n\nThe variables `SOCIAL`, `ENVIRONMENTAL` and `EDUCATIONAL` can be used to programmatically represent the choice values. Once the class is created, their values are no longer a tuples, but only the database fields (so `CharityType.ENVIRONMENTAL` is equal to `'ENV'`). So you can do:\n\n```py\ncharity = Charity()\ncharity.charity_type = CharityType.ENVIRONMENTAL\ncharity.save()\n```\n\nAnother field generated magically is `VALUE_MAPPER`. It is a dictionary, where the keys represent the database values and the dictionary values represent the variable name used to declare the options. In our example `VALUE_MAPPER` look like this:\n\n```py\n>>> CharityType.VALUE_MAPPER\n{\n 'SOC': 'SOCIAL',\n 'ENV': 'ENVIRONMENTAL',\n 'EDU': 'EDUCATIONAL'\n\n}\n```\n\nThis is useful if you need to use the variable names a codes (for a REST API for instance), because the user readable values might be subjects of translation.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/eeriksp/django-model-choices", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-model-choices", "package_url": "https://pypi.org/project/django-model-choices/", "platform": "", "project_url": "https://pypi.org/project/django-model-choices/", "project_urls": { "Homepage": "https://gitlab.com/eeriksp/django-model-choices" }, "release_url": "https://pypi.org/project/django-model-choices/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Django Model Choices provides a neat and DRY way to specify the `choices` option for a Django models and forms.", "version": "1.0.0" }, "last_serial": 4797135, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "f05efc6ea03fb7eeed8d7eb6f251c35a", "sha256": "9e1bce995202868debcac17b99782554a371bab78cc8c053aa90a8ab36ef1aaa" }, "downloads": -1, "filename": "django_model_choices-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f05efc6ea03fb7eeed8d7eb6f251c35a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4435, "upload_time": "2019-02-08T19:43:42", "url": "https://files.pythonhosted.org/packages/15/7d/1d76b97d4ccb0c850275a9748c62813fa3cd19b4d11e50618b060bb54d27/django_model_choices-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3af59be7417ee471feee77cca9baf72f", "sha256": "da9c2904870db241c3a8394c7bd5fedc0cc6313af496b4adfd9c39feb7119113" }, "downloads": -1, "filename": "django-model-choices-1.0.0.tar.gz", "has_sig": false, "md5_digest": "3af59be7417ee471feee77cca9baf72f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2946, "upload_time": "2019-02-08T19:43:44", "url": "https://files.pythonhosted.org/packages/0c/b9/adf5d72c21eabd7bc4e89d783f2758ec3e7695635cc5b81ac524c36b6fbf/django-model-choices-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f05efc6ea03fb7eeed8d7eb6f251c35a", "sha256": "9e1bce995202868debcac17b99782554a371bab78cc8c053aa90a8ab36ef1aaa" }, "downloads": -1, "filename": "django_model_choices-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f05efc6ea03fb7eeed8d7eb6f251c35a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4435, "upload_time": "2019-02-08T19:43:42", "url": "https://files.pythonhosted.org/packages/15/7d/1d76b97d4ccb0c850275a9748c62813fa3cd19b4d11e50618b060bb54d27/django_model_choices-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3af59be7417ee471feee77cca9baf72f", "sha256": "da9c2904870db241c3a8394c7bd5fedc0cc6313af496b4adfd9c39feb7119113" }, "downloads": -1, "filename": "django-model-choices-1.0.0.tar.gz", "has_sig": false, "md5_digest": "3af59be7417ee471feee77cca9baf72f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2946, "upload_time": "2019-02-08T19:43:44", "url": "https://files.pythonhosted.org/packages/0c/b9/adf5d72c21eabd7bc4e89d783f2758ec3e7695635cc5b81ac524c36b6fbf/django-model-choices-1.0.0.tar.gz" } ] }