本文整理汇总了Python中models.Vote.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.objects方法的具体用法?Python Vote.objects怎么用?Python Vote.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.objects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import objects [as 别名]
def post():
values = {}
vote_value = request.form['vote']
vote = Vote()
for item in request.form.getlist('value[]'):
if vote.get_vote_title(item) is not None:
values[item] = vote.get_vote_title(item)
elif int(item) == Vote.CUSTOM_VOTE_ID and vote_value:
values[item] = vote_value
if values:
# add vote
vote.ip = request.remote_addr
vote.votes = values
try:
vote_current = Vote.objects(ip=request.remote_addr,
created_at__gte=(datetime.datetime.now() - datetime.timedelta(minutes=15)))
if vote_current:
raise ValueError("You've already voted!")
vote.save()
suffix = VoteView.ordinal(len(Vote.objects))
return jsonify({'status': 'ok',
'message': 'Thank your for voting! You are the %s fan of python' % suffix})
except ValueError as e:
return jsonify({'status': 'error', 'message': e.message})
except Exception:
return jsonify({'status': 'error', 'message': 'Error while saving vote. Sorry :('})
else:
return jsonify({'status': 'error', 'message': 'Choose any option to vote'})
示例2: total_voted_last_month
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import objects [as 别名]
def total_voted_last_month():
"""
Get total number of people voted for last 31 days
:return: int
"""
return len(Vote.objects(created_at__gte=(datetime.datetime.now() - datetime.timedelta(days=31))))