![](/img/trans.png)
[英]How do I make the numbers on the y-axis show values in millions instead of in scientific notation in matplotlib?
[英]How do I make a form's Choice Field values show the actual values on a page instead of numbers?
我的表单 ( NewListing
) 中有一个字段 ( categories
) 应该有 4 个值,可以在我的一个页面上的表单中选择这些值。 但是,当我想显示选择了哪个值时,我得到一个数字而不是值。
这些值为:
因此,如果之前选择了New
,当这个值显示在另一个页面上时,它会显示为1
而不是New
。
我该如何解决?
模型.py:
class Listing(models.Model):
...
condition = models.CharField(max_length=20)
forms.py:
condition_choices = (
(1, 'New'),
(2, 'Refurbished'),
(3, 'Opened'),
(4, 'Used'),
)
class NewListing(forms.Form):
...
condition = forms.ChoiceField(choices=condition_choices, widget=forms.Select(attrs={
'class': 'condition',
}))
html :(不相关,但显示了它将在哪里使用 - 虽然它在另一个页面上选择了 - 这很好用)
<div class="condition">
<p> Condition: <strong> {{ listing.condition }} </strong></p>
</div>
用人类友好的值替换元组中的元素。
CONDITION_CHOICES = [
('NEW', 'New'),
('REF', 'Refurbished'),
('OPE', 'Opened'),
('USE', 'Used'),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.