假设我有以下Django (3.2)代码:
class AType(models.IntegerChoices):
ZERO = 0, 'Zero'
ONE = 1, 'One'
TWO = 2, 'Two'
a = AType.ZERO
如何获取"Zero“(与a
关联的字符串)?
这与this question非常相似,不同之处在于这里我们只有IntegerChoices对象,没有关联的模型对象。
发布于 2021-11-22 14:53:56
您可以使用.label
>>> a = AType.ZERO
>>> a.label
'Zero'
https://stackoverflow.com/questions/70073226
复制相似问题