假設我有以下 Django (3.2) 代碼:
class AType(models.IntegerChoices):
ZERO = 0, 'Zero'
ONE = 1, 'One'
TWO = 2, 'Two'
a = AType.ZERO
如何獲得“零”(與 關聯的字串a)?
這與這個問題非常相似,除了這里我們只有 IntegerChoices 物件,而不是關聯的模型物件。
uj5u.com熱心網友回復:
您可以使用.label:
>>> a = AType.ZERO
>>> a.label
'Zero'
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/364062.html
