我有以下型号
class Article(models.Model):
title = models.CharField(max_length=255, db_index=True)
slug = UniqueSlugField(prepopulate_from='title', unique=True)
favorited = models.ManyToManyField(to=User, blank=True)
tags = TaggableManager()
...
class Vote(models.Model):
article = models.ForeignKey(to=Article)
voter = models.ForeignKey(to=User, related_name='voter')
timestamp = models.DateTimeField(auto_now_add=True)
...
我使用以下代码行以降序获取所选标签的热门文章
Vote.objects.filter(tags__in=[tag]).annotate(num_articles=Count('article')).order_by('-num_articles')
如何构建orm查询,通过模型的以下字段获取热门Article.favorited
文章Vote
?
谢谢,
苏丹