本文整理汇总了Python中models.Vote.object_id方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.object_id方法的具体用法?Python Vote.object_id怎么用?Python Vote.object_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.object_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import object_id [as 别名]
def vote(request, id):
this_topic = Topic.objects.get(pk=id)
is_voted = False
try:
vote_thistopic = this_topic.votes.get(user=request.user.get_profile())
is_voted = True
except:
pass
if is_voted is False:
this_vote = Vote(user=request.user.get_profile())
# this_topic.votes.add(user = request.user)
topic_type = ContentType.objects.get_for_model(Topic)
this_vote.content_type = topic_type
this_vote.object_id = this_topic.id
this_vote.save()
# update vote count
this_topic.save()
return redirect(reverse(topic, args=[this_topic.id]))