django-choices-enums 用于 django 的枚举开源项目

我要开发同款
匿名用户2019年11月10日
40阅读
开发技术Python
所属分类程序开发、常用工具包
授权协议GPL

作品详情

django-choices-enums

django-choices-enums 是用于django的枚举。

此实现特点:

不缺失choices的可读说明能支持代码提示轻量,方便使用,无侵入安装pipinstalldjango-choices-enums使用

完整文档见:https://github.com/gojuukaze/django-choices-enums

fromdjango_choices_enumsimportDjangoChoicesEnumclassTypeChoices(DjangoChoicesEnum):Created=(1,'created')Finished=(2,'finished')anonymous=((3,'xx'),(4,'xx'),)classFoo(models.Model):type=models.IntegerField(choices=TypeChoices.to_django_choices())使用枚举f=Foo.create(type=TypeChoices.Created)获取所有可选值print(TypeChoices.all_values())#Out:(1,2,3,4)获取说明print(TypeChoices.Created.verbose)#Out:createdprint(TypeChoices.get_verbose(2))#Out:finishedprint(TypeChoices.get_verbose(3))#Out:xxprint(TypeChoices.get_verbose(TypeChoices.B))#Out:finished
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论