获取小组的帖子,没有根据group_id来获取
来源:11-16 获取小组内的帖子和热门帖子

liyanan_nn
2018-12-27
class PostHandler(RedisHandler):
@authenticated_async
async def get(self,group_id, *args, **kwargs):
#获取小组内的帖子
post_list = []
try:
group = await self.application.objects.get(CommunityGroup, id=int(group_id))
group_member = await self.application.objects.get(CommunityGroupMember, user=self.current_user,
community=group, status="agree")
posts_query = Post.extend()
c = self.get_argument("c", None)
if c == "hot":
posts_query = posts_query.filter(Post.is_hot == True)
if c == "excellent":
posts_query = posts_query.filter(Post.is_excellent == True)
posts = await self.application.objects.execute(posts_query)
for post in posts:
item_dict = {
"user":{
"id":post.user.id,
"nick_name": post.user.nick_name
},
"id":post.id,
"title":post.title,
"content":post.content,
"comment_nums":post.comment_nums
}
post_list.append(item_dict)
没有根据group_id来获取,点击任何一个小组,得到的都是所有的帖子。
写回答
1回答
-
bobby
2019-01-01
这里有group的id啊
022019-01-03
相似问题