• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

django-choices-enums: The enum type used for Django choices enables Django's ...

原作者: [db:作者] 来自: 网络 收藏 邀请

django-choices-enums

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

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

feature

  • the human-readable name of choices not missing. 不缺失 choices 的可读说明
  • code hints. 能支持代码提示
  • Lightweight, easy to use. 方便使用、轻量、无侵入

依赖

  • python3+

Installation

pip install django-choices-enums

Usage

from django_choices_enums import DjangoChoicesEnumclass 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 DjangoChoicesEnumclass 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 DjangoChoicesEnumclass 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: 33print(MyEnum.get_verbose(MyEnum.B))# Out: B ...

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap