gpt4 book ai didi

python - 对象没有属性 'get_notification_display'

转载 作者:行者123 更新时间:2023-12-01 02:57:28 25 4
gpt4 key购买 nike

我正在尝试显示选择字段的人类可读标签。

def reminder(request, pk=None):
reminder = get_object_or_404(Reminder, pk=pk)
print(reminder.id) # printing correct value
print(reminder.get_notification_display())
return render(request, 'reminder.html', {'reminder': reminder, 'title': 'Reminder'})

但是它抛出了这个错误:

AttributeError: 'Reminder' object has no attribute 'get_notification_display'

这是模型:

class Reminder(models.Model):
provider_type = (
('Em', 'Email'),
('Sm', 'SMS'),
('De', 'Desktop'),
('Mo', 'Mobile'),
)
notification = ArrayField(models.CharField(choices=provider_type, max_length=2, default='Em'))

这是关于 get_FOO_display 的文档- 我错过了什么?

最佳答案

documentation

For every field that has choices set, the object will have a get_FOO_display() method

但你没有 choices设置为通知。换句话说,您的类中需要一个 NOTIFICATION_CHOICES 可迭代对象,其长度为两个可迭代对象。

关于python - 对象没有属性 'get_notification_display',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com