所以,我有微博系统,每个博客都用一些简单的帖子调用板。任何用户都可以在那里创建一个版块,并订阅其他用户的版块。为了管理订阅,我创建了一个 manytomanyfield 成员资格类。问题是如何从数据库中获取用户订阅的所有板块的所有帖子。我的模型代码:
class Board (models.Model):
title = models.CharField (max_length=30)
description = models.CharField (max_length=300)
author = models.ForeignKey(User)
created = models.DateTimeField (editable=False)
subscribers = models.ManyToManyField(User, through="Subscription")
class Post (models.Model):
title = models.CharField (max_length=30)
description = models.CharField (max_length=320)
created = models.DateTimeField (editable=False)
board = models.ForeignKey (Board)
class Subscription (models.Model):
subcsriber = models.ForeignKey(User)
board = models.ForeignKey(Board)
sub_date = models.DateTimeField (auto_now_add=True)
所以我有能力在一个回复中从所有板上获取所有排序帖子的列表。或者我应该先获取所有的板列表,然后将彼此的所有帖子合并到一个列表中,然后按发布日期排序?