Beispiel #1
0
 def create(self, validated_data):
     try:
         validated_data['feed'] = Feed.objects.get(
             id=validated_data['feed']['id'], is_deleted=False)
     except Rss.DoesNotExist as e:
         raise exceptions.CustomException(
             detail=ugettext('Feed does not exist.'))
     validated_data['user'] = self.context['request'].user
     comment = Comment(**validated_data)
     comment.save()
     return comment
Beispiel #2
0
def add_comment(request):
    if request.method == 'POST':
        if 'comment' not in request.POST:
            return HttpResponse(status=400)

        if 'article' not in request.POST:
            return HttpResponse(status=400)

        user = request.user
        author = user
        comment = request.POST['comment']
        article_pk = int(request.POST['article'])

        comment_obj = Comment()
        comment_obj.author = author
        comment_obj.comment = comment
        comment_obj.article = News.objects.get(pk=article_pk)
        comment_obj.save()

    return HttpResponse(user.first_name + user.last_name, status=200)