【发布时间】:2019-01-12 19:12:42
【问题描述】:
我有这个模型:
class Rank(models.Model):
RANK_TYPE_CHOICES = (
('O', 'Officer'),
('E', 'Enlisted'),
('V', 'Civilian'),
('C', 'Cadet'),
)
ShortName = models.CharField(max_length=50)
LongName = models.CharField(max_length=500)
Type = models.CharField(max_length=1, choices=RANK_TYPE_CHOICES, default='O')
Genre = models.ForeignKey(Genre, on_delete=models.DO_NOTHING)
Career = models.ForeignKey(Career, on_delete=models.DO_NOTHING)
image = models.ForeignKey(Photos, on_delete=models.DO_NOTHING)
当我执行这个 ORM 操作时:
models.Rank.objects.values('Type').annotate(total=Count('Type')).order_by()
我收到此回复
<QuerySet [{'Type': 'O', 'total': 1}]>
完全如我所愿。 但是,如您所见,它给了我短类型。如何让它显示长名称而不是类型选择短名称?
谢谢。
【问题讨论】:
标签: django python-3.x django-models django-orm