抱歉,如果问题本身令人困惑。我有一个模型,其中有两个列表用作下拉列表供用户选择。一切正常,除了在查看数据时它只会在我希望它显示值时显示键。models.pyclass RestroomReview(models.Model): MEN = 'M' WOMEN = 'W' UNISEX = 'U' FAMILY = 'F' RESTROOM_TYPE_CHOICES = [ ('M', 'Men'), ('W', 'Women'), ('U', 'Unisex'), ('F', 'Family') ] RATING_CHOICES = [ (1, 'Poor'), (2, 'Average'), (3, 'Good'), (4, 'Very Good'), (5, 'Excellent') ] venue = models.ForeignKey(Venue, blank=False, on_delete=models.CASCADE) user = models.ForeignKey('auth.User', blank=False, on_delete=models.CASCADE) public = models.BooleanField(blank=False) rest_type = models.CharField( max_length=1, choices=RESTROOM_TYPE_CHOICES, default=MEN ) baby = models.BooleanField('Changing Table') needle = models.BooleanField('Sharps Container') handicap = models.BooleanField('Handicap Accessible') rating = models.IntegerField(choices=RATING_CHOICES, default=1) title = models.CharField(max_length=200, blank=False) comment = models.TextField(max_length=1000, blank=False) posted_date = models.DateTimeField(blank=False)review_detail.html{% extends 'restroom_rater/base.html' %}{% block content %}<div> <h3>{{ review.venue.name }}</h3> <p>Title: {{ review.title}}</p> <p>by {{ review.user }}</p> <p>Public: {{ review.public }}</p> <p>Type: {{ review.rest_type }}</p> <p>Changing Table: {{ review.baby }}</p> <p>Sharps Container: {{ review.needle }}</p> <p>Handicap Accessible: {{ review.handicap }}</p> <p>Rating: {{ review.rating }}</p> <p>Comment: {{ review.comment }}</p> <p>Date Posted: {{ review.posted_date }}</p></div>{% endblock %}所以在我的 review_detail 模板中,我希望它显示“Men”、“Women”、“Unisex”或“Family”,但它显示的是“M”、“W”、“U”、“F”。评级也一样。我希望它显示“差”、“好”等,但它给出了数字评级。
1 回答
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
我想你在找
{{ review.get_rest_type_display }}
一般get_FIELDNAME_display()
会给你显示值。
添加回答
举报
0/150
提交
取消