djago-choices-eums
djago-choices-eums 是用于djago的枚举。
此实现特点:
不缺失choices的可读说明能支持代码提示轻量,方便使用,无侵入安装pipistalldjago-choices-eums使用完整文档见:https://github.com/gojuukaze/djago-choices-eums
fromdjago_choices_eumsimportDjagoChoicesEumclassTypeChoices(DjagoChoicesEum):Created=(1,'created')Fiished=(2,'fiished')aoymous=((3,'xx'),(4,'xx'),)classFoo(models.Model):type=models.ItegerField(choices=TypeChoices.to_djago_choices())使用枚举f=Foo.create(type=TypeChoices.Created)获取所有可选值prit(TypeChoices.all_values())#Out:(1,2,3,4)获取说明prit(TypeChoices.Created.verbose)#Out:createdprit(TypeChoices.get_verbose(2))#Out:fiishedprit(TypeChoices.get_verbose(3))#Out:xxprit(TypeChoices.get_verbose(TypeChoices.B))#Out:fiished






评论