我在'聚合'和'最新'方面遇到了困难。
我有这两个模型:
class Word(models.Model):
ESSENTIALWORDS = 'EW'
FOOB = 'ER'
OTHER = 'OT'
WORDSOURCE_TYPE_CHOICES = (
(ESSENTIALWORDS, 'Essential Words'),
(FOOB, 'FOOB'),
(OTHER, 'OTHER'),
)
level = models.IntegerField()
word = models.CharField(max_length=30)
source = models.CharField(max_length=2,
choices=WORDSOURCE_TYPE_CHOICES,
default=OTHER)
hint = models.CharField(max_length=30, null=True, blank=True)
class Attempt(models.Model):
learner = models.ForeignKey(Learner)
word = models.ForeignKey(Word)
when = models.DateTimeField(auto_now_add=True)
success = models.BooleanField(default=False)
我想查找最新Word
(基于字段Attempt
)的when
值为True的所有success
个对象。