class AdminPostSerializer(HyperlinkedModelSerializer):
    parent_lookup_kwargs = {
        'user_pk': 'user__pk',
    }

    user = UserSerializer(read_only=True)
    comments = PostCommentSerializer(many=True, read_only=True)
    images = PostImageSerializer(many=True, read_only=True)

    class Meta:
        model = Post
        fields = (
            'url',
            'id',
            'user',
            'title',
            'description',
            'short_description',
            'approved',
            'likes',
            'dislikes',
            'datetime_created',
            'datetime_modified',
            'comments',
            'images',
        )
        read_only_fields = (
            'likes',
            'dislikes',
        )
        depth = 1
Beispiel #2
0
    def post(self, request, pk, format=None):
        comment = PostComment.objects.get(id=pk)

        images = request.data.getlist('images')

        imageids = []
        for image in images:
            image_obj = PostFiles()
            image_obj.name = image.name
            image_obj.image = image
            image_obj.save()
            comment.images.add(image_obj)
            imageids.append(image_obj.id)

        images = PostFiles.objects.filter(id__in=imageids)
        serializer = PostImageSerializer(images, many=True)

        return Response(serializer.data)
Beispiel #3
0
    def post(self, request, format=None):
        images = request.data.getlist('images')

        try:
            commentid = request.data['commentid']
            comment = PostComment.objects.get(id=int(commentid))
        except:
            comment = False

        imageids = []
        for image in images:
            image_obj = PostFiles()
            image_obj.name = image.name
            image_obj.image = image
            image_obj.save()
            imageids.append(image_obj.id)
            if comment:
                comment.images.add(image_obj)

        images = PostFiles.objects.filter(id__in=imageids)
        serializer = PostImageSerializer(images, many=True)

        return Response(serializer.data)
Beispiel #4
0
 def get(self, request):
     queryset = PostImage.objects.all()
     serializer = PostImageSerializer(queryset, many=True)
     return Response(serializer.data)
Beispiel #5
0
 def get(self, request, pk, format=None):
     comment = PostComment.objects.get(id=pk)
     images = comment.images.all().order_by('id')
     serializer = PostImageSerializer(images, many=True)
     return Response(serializer.data)