{"id":20977314,"url":"https://github.com/2degrees/django-enum-field","last_synced_at":"2026-04-27T14:31:49.946Z","repository":{"id":139812135,"uuid":"71805360","full_name":"2degrees/django-enum-field","owner":"2degrees","description":"A Django field for use with https://github.com/2degrees/python-enumeration.","archived":false,"fork":false,"pushed_at":"2017-04-11T15:16:54.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-12-31T00:31:47.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2degrees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-24T15:51:42.000Z","updated_at":"2017-05-29T20:02:02.000Z","dependencies_parsed_at":"2024-08-24T21:15:41.953Z","dependency_job_id":null,"html_url":"https://github.com/2degrees/django-enum-field","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/2degrees/django-enum-field","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fdjango-enum-field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fdjango-enum-field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fdjango-enum-field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fdjango-enum-field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2degrees","download_url":"https://codeload.github.com/2degrees/django-enum-field/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fdjango-enum-field/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32341447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T04:58:17.605Z","updated_at":"2026-04-27T14:31:49.927Z","avatar_url":"https://github.com/2degrees.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/2degrees/django-enum-field.svg?branch=master)](https://travis-ci.org/2degrees/django-enum-field) \n[![Coverage Status](https://coveralls.io/repos/github/2degrees/django-enum-field/badge.svg?branch=master)](https://coveralls.io/github/2degrees/django-enum-field?branch=master)\n\n# django-enum-field\n\nA Django field for use with [python-enumeration](https://github.com/2degrees/python-enumeration).\n\n## Getting started\n\ndjango-enum-field can be installed from PyPi via:\n\n```bash\npip install django-enum-field\n```\n\n## Using in your models\n\n```python\n\u003e\u003e\u003e from django.db.models import Model\n\u003e\u003e\u003e from enum_field import Enum, EnumField\n\u003e\u003e\u003e CLOTHING_SIZES = Enum(\n...     ('xs', 'EXTRA_SMALL'),\n...     ('s', 'SMALL'),\n...     ('m', 'MEDIUM'),\n...     ('l', 'LARGE'),\n...     ('xl', 'EXTRA_LARGE'),\n...     ('xxl', 'EXTRA_EXTRA_LARGE'),\n... )\n\u003e\u003e\u003e class ClothingItem(Model):\n...     size = EnumField(CLOTHING_SIZES)\n```\n\nYou can now use the enum in your look-ups:\n\n```python\n\u003e\u003e\u003e ClothingItem.objects.filter(size=CLOTHING_SIZES.SMALL)\n[...]\n\u003e\u003e\u003e ClothingItem.objects.filter(size__in=CLOTHING_SIZES.SMALL.subsequent_values)\n```\n\nYou can set the field value to an enum item:\n\n```python\n\u003e\u003e\u003e item = ClothingItem.objects.create(size=CLOTHING_SIZES.LARGE)\n```\n\nIf you're using Django forms, you can specify UI labels for your enum\nand they'll be used in any model forms:\n\n```python\n\u003e\u003e\u003e # Before defning the model:\n\u003e\u003e\u003e CLOTHING_SIZES.set_ui_labels({\n...     CLOTHING_SIZES.EXTRA_SMALL: 'Extra small',\n...     CLOTHING_SIZES.SMALL: 'Small',\n...     CLOTHING_SIZES.MEDIUM: 'Medium',\n...     CLOTHING_SIZES.LARGE: 'Large',\n...     CLOTHING_SIZES.EXTRA_LARGE: 'Extra large',\n...     CLOTHING_SIZES.EXTRA_EXTRA_LARGE: 'Extra extra large',\n... })\n\u003e\u003e\u003e ClothingItem._meta.get_field('size').choices\n((\u003cEnumItem: value='xs', index=0\u003e, 'Extra small'), (\u003cEnumItem: value='s', index=1\u003e, 'Small'), (\u003cEnumItem: value='m', index=2\u003e, 'Medium'), (\u003cEnumItem: value='l', index=3\u003e, 'Large'), (\u003cEnumItem: value='xl', index=4\u003e, 'Extra large'), (\u003cEnumItem: value='xxl', index=5\u003e, 'Extra extra large'))\n\u003e\u003e\u003e # If you're not using ModelForm, but want the choices:\n\u003e\u003e\u003e CLOTHING_SIZES.get_ui_labels()\n((\u003cEnumItem: value='xs', index=0\u003e, 'Extra small'), (\u003cEnumItem: value='s', index=1\u003e, 'Small'), (\u003cEnumItem: value='m', index=2\u003e, 'Medium'), (\u003cEnumItem: value='l', index=3\u003e, 'Large'), (\u003cEnumItem: value='xl', index=4\u003e, 'Extra large'), (\u003cEnumItem: value='xxl', index=5\u003e, 'Extra extra large'))\n```\n\n## Migrations\n\n`EnumField` is full deconstructible and is, therefore, compatible with \nDjango's migration system. **Please note**, to make the underlying `Enum`\nand `EnumItem` compatible with Django's migration system, you _must_\nuse the sub-classes available from `enum_field.Enum` and \n`enum_field.EnumItem` and *not* from the `python-enumeration` project.\n\n\n# Changelog\n\n## Version 1.0 Beta 1 (2017-04-11)\n\n- Fell back to using the enum values in the field `choices` if the UI labels\n  are not set.\n- **Backwardly incompatible:** Dropped ability to set custom field choices.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2degrees%2Fdjango-enum-field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2degrees%2Fdjango-enum-field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2degrees%2Fdjango-enum-field/lists"}