我正在尝试找到解决我的问题的方法。
模型.py
class Article(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField()
description = models.TextField()
def archive_quality(self):
return self.archive_set.order_by('-quality').distinct().values_list('quality', flat=True)
class Archive(models.Model):
CHOICES_QUALITY = (
('1', 'HD YB'),
('2', 'HD BJ'),
('3', 'HD POQD'),
('4', 'HD ANBC'),
)
article = models.ForeignKey(Article)
quality = models.CharField(max_length=100, choices=CHOICES_QUALITY)
档案.html
{% for article in articles %}
{{ article }}
{% for quality in article.archive_quality %}
{{ quality.get_quality_display }}#This is not working
{% endfor %}
{% endfor %}
更新 功能 archive_quality 很重要,因为它可以防止模板对象中的重复出现。
Example:
article:
My article one
Archive:
quality: 1111222333 >> without the function
quality: 123 >> with function