获取小组的帖子,没有根据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

//img.mukewang.com/szimg/5c2b44050001278908520517.jpg 这里有group的id啊

0
2
bobby
回复
liyanan_nn
这里调用的是get方法 如果获取不到数据的话会抛出异常的, 所以这里的目的是为了验证用户是有权限的, 不是为了使用这个变量的
2019-01-03
共2条回复

Tornado从入门到进阶 打造支持高并发的技术论坛

异步IO并发编程/Form,ORM/aiomysql、peewee-async/epoll

593 学习 · 350 问题

查看课程