#NEWLINE# @ detail_route ( methods = [ 'POST' ] , permission_classes = [ permissions . IsAuthenticated ] ) #NEWLINE# def helpful( self , request , pk = None ) : #NEWLINE# #INDENT# answer = self . get_object ( ) #NEWLINE# if ( not answer . question . editable ) : #NEWLINE# #INDENT# raise GenericAPIException ( 403 , 'Answer not editable' ) #NEWLINE# #UNINDENT# if answer . has_voted ( request ) : #NEWLINE# #INDENT# raise GenericAPIException ( 409 , 'Cannot vote twice' ) #NEWLINE# #UNINDENT# AnswerVote ( answer = answer , creator = request . user , helpful = True ) . save ( ) #NEWLINE# num_helpful_votes = AnswerVote . objects . filter ( answer = answer , helpful = True ) . count ( ) #NEWLINE# num_unhelpful_votes = AnswerVote . objects . filter ( answer = answer , helpful = False ) . count ( ) #NEWLINE# return Response ( { #NEWLINE# #INDENT# 'num_helpful_votes' : num_helpful_votes , #NEWLINE# 'num_unhelpful_votes' : num_unhelpful_votes , #NEWLINE# #UNINDENT# } )