【发布时间】:2019-09-30 18:40:50
【问题描述】:
假设我有一些类如下:
from django.db import models
REVIEW_RATING_CHOICES = (
(5, 'Five'),
(4, 'Four'),
(3, 'Three'),
(2, 'Two'),
(1, 'One'),
)
class Publication(models.Model):
name = models.CharField()
class Article(models.Model):
publication = models.ForeignKey(Publication)
content = models.TextField()
class Review(models.Model):
date = models.DateTimeField()
article = models.ForeignKey(Article)
rating = models.IntegerField(choices=REVIEW_RATING_CHOICES)
假设我们想要突出“非常好的”出版物,我们将其定义为任何文章立即获得五星评价的出版物。
我如何获得一篇文章的第一个(即 Review.date 的最早值)评论中的任何个获得 5 颗星的出版物计数? p>
【问题讨论】: