PAYCODE_BLUEPAY = "BLUEPAY"
PAYCODE_HEARTLAND = "HEARTLAND"
PAYCODE_1STPAY = "1STPAYMENT"
PAYCODE_CHOICES =(
(PAYCODE_1STPAY, '1St Payment'),
(PAYCODE_BLUEPAY, 'Bluepay Payment'),
(PAYCODE_HEARTLAND, 'HeartLand Payment'),
)
class Payment(models.Model):
paymentmethod = models.CharField("Payment Method", max_length=20, choices = PAYCODE_CHOICES, blank=False, null=False)
def __str__(self):
return self.paymentmethod
__str__(self)
方法将返回 BLUEPAY
或 HEARTLAND
或 1STPAYMENT
。但我想要 __str__(self)
返回 1St Payment 、 Bluepay Payment 或 HeartLand Payment 。请给我解决方案。谢谢。
最佳答案
def __str__(self):
return self.get_paymentmethod_display()
见 get_FOO_display()
关于django - Django 中字段选择的 “human-readable” 值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47881817/