Skip to main content

The enum type used for Django choices enables Django's choices to support code prompts!!

Project description

django-choices-enums

The enum type used for Django choices enables Django’s choices to support code prompts!!

用于django choices的枚举类型,使得django的choices支持代码提示!!

依赖

  • python3+

Installation

pip install django-choices-enums

Usage

from django_choices_enums import DjangoChoicesEnum

class TypeChoices(DjangoChoicesEnum):
    Created = (1,'created')
    Finished = (2,'finished')

class Foo(models.Model):
    type = models.IntegerField(choices=TypeChoices.to_django_choices())
  • use enum like this:

f = Foo.create(type=TypeChoices.Created)
  • get all values:

print(TypeChoices.all_values())
# Out: [1, 2]
  • anonymous values:

from django_choices_enums import DjangoChoicesEnum

class MyEnum(DjangoChoicesEnum):
    A = (1, 'xxx')
    B = (2, 'xxx')

    anonymous = ((3, 'xx'),
                 (4, 'xx'),
                 )

print(MyEnum.all_values())
# Out: [(1, 'xxx'), (2, 'xxx'), (3, 'xx'), (4, 'xx')]
  • get verbose:

from django_choices_enums import DjangoChoicesEnum

class MyEnum(DjangoChoicesEnum):
    A = (1, 'A ...')
    B = (2, 'B ...')

    anonymous = ((3, '33'),
                 (4, '44'),
                 )
print(MyEnum.A.verbose)
# Out: A ...
print(MyEnum.get_verbose(2))
# Out: B ...
print(MyEnum.get_verbose(3))
# Out: 33
print(MyEnum.get_verbose(MyEnum.B))
# Out: B ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-choices-enums-1.0.3.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file django-choices-enums-1.0.3.tar.gz.

File metadata

  • Download URL: django-choices-enums-1.0.3.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

File hashes

Hashes for django-choices-enums-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1073c4f25cf80d9e5b482fdba600250a6f993ce85c3127d32b764507f86d2814
MD5 b5f26d58fe02b342186762321e7d8558
BLAKE2b-256 d3202c01ae7d974230b18f589fbbafaf183910fa99f194b2bf60f5c3a13b171c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page