Skip to content

Instantly share code, notes, and snippets.


krakiun/ Secret

Created February 26, 2018 22:48
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
def api_service_vote(product_id, direction):
''' thi api need for vote up/down the services'''
product = Product.query.get_or_404(product_id)
query = Product_Vote.query.filter(Product_Vote.voter_id ==,
Product_Vote.product_id ==
if db.session.query(query.exists()).scalar():
raise APIError('You already vote')
if direction == 'up':
product.votes = Product.votes + 1
product.votes = Product.votes - 1
vote = Product_Vote(,,
up=direction == 'up',
down=direction == 'down'
return json.jsonify()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment