示例#1
0
    def create(self, request, *args, **kwargs):
        try:
            data = self.take_data_from_request(request)
            serializer = PostSerializer(data=data)
            serializer.is_valid(raise_exception=True)

            post = serializer.save()
            post_data = post.__dict__
            if '_state' in post_data:
                del post_data['_state']

            return Response(post_data, status=status.HTTP_200_OK)

        except Exception as exception:
            raise exception
示例#2
0
文件: post.py 项目: mungpham/mungpham
    def list(self, request):
        try:
            queryset = Posts.objects.all().filter(user_id=request.user.id)
            serializer = PostSerializer(queryset, many=True)
            return Response(serializer.data)

        except Exception as exception:
            raise exception
示例#3
0
    def retrieve(self, request, pk=None, **kwargs):
        try:
            post = self.get_and_check(pk)
            serializer = PostSerializer(post)

            return Response(serializer.data)

        except Exception as exception:
            raise exception
示例#4
0
文件: post.py 项目: mungpham/mungpham
    def get_list_post_of_friend(self, request):
        try:
            get_friend = Friend.objects.all().filter(user_id=1)
            for i in get_friend:
                queryset = Posts.objects.all().filter(user_id=i.friend_user_id)
                serializer = PostSerializer(queryset, many=True)
            return Response(serializer.data)

        except Exception as exception:
            raise exception