楷模
class post(models.Model):
post_content = models.CharField(u'Treść:', max_length=65000)
post_thread = models.ForeignKey(thread)
post_user = models.ForeignKey(user)
post_date = models.DateTimeField()
objects = post_manager()
class thread(models.Model):
thread_title = models.CharField(u'Nazwa tematu:', max_length=100)
thread_content = models.CharField(u'Treść:', max_length=65000)
thread_forum = models.ForeignKey(forum, null=True)
thread_subforum = models.ForeignKey(subforum, null=True)
thread_tag = models.CharField(u'Tagi', null=True, max_length=100)
thread_user = models.ForeignKey(user)
thread_date = models.DateTimeField()
thread_write = models.BooleanField()
thread_sticky = models.BooleanField()
objects = thread_manager()
意见
thread_list = thread.objects.select_related().filter(thread_forum_id = current_obj.id).order_by('-thread_date')
for thread in thread_list:
count = post.objects.select_related().filter(post_thread_id = thread.id).count()
thread.post = count
thread_list 没有帖子编号帖子有 ForeignKey 到线程
我能做些什么来达到这样的效果?我想将数字帖子添加到 thread_list