本文整理汇总了Python中models.Score.save方法的典型用法代码示例。如果您正苦于以下问题:Python Score.save方法的具体用法?Python Score.save怎么用?Python Score.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Score
的用法示例。
在下文中一共展示了Score.save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def request(request):
if request.method == "GET":
rg = request.GET
player = Player.objects.get(id=request.session['user_id'])
if 'new_player_name' in rg:
player.name = rg['new_player_name']
player.save()
return HttpResponse(json.dumps({"result": "success", "player_name": rg['new_player_name']}))
if 'new_max_score' in rg:
game_name = rg['game_name']
score = None
try:
score = Score.objects.get(player=player, game__name=game_name)
except:
score = Score(player=player, game=Game.objects.get(name=game_name), score=0)
score.score = rg['new_max_score']
score.save()
return HttpResponse(json.dumps({"result": "success", "max_score": rg['new_max_score']}))
if 'max_score_records' in rg:
game_name = rg['game_name']
count = rg['count']
max_score_records = []
for record in Score.objects.filter(game__name=game_name).order_by('-score')[:10]:
max_score_records.append({"score": record.score, "player_name": record.player.name})
return HttpResponse(json.dumps(max_score_records))
示例2: test_float_serialization
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def test_float_serialization(self):
"""Tests that float values serialize and deserialize intact"""
sc = Score(score=3.4)
sc.save()
serial_str = serializers.serialize(self.serializer_name, [sc])
deserial_objs = list(serializers.deserialize(self.serializer_name,
serial_str))
self.assertEqual(deserial_objs[0].object.score, Approximate(3.4, places=1))
示例3: post
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def post(self, request):
score = request.POST.get('score')
question_id = request.POST.get('question_id')
question = Question.objects.get(pk=question_id)
score = Score(question=question,user=request.user,score=int(score))
score.save()
return HttpResponse(status=201)
示例4: submit
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def submit(user):
try:
score_ = submit_score(request.form.to_dict())
except MultipleInvalid as e:
return show_errors(e)
score = Score(value=score_['score'], user=user)
score.save()
return {"success": True}
示例5: create_score
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def create_score(registered_client):
score = Score()
score.registered_client = registered_client
score.played_on = timezone.now()
score.recieved_on = timezone.now()
score.play_time = random.randint(2000, 30000)
score.altitude = random.randint(0, 2000)
score.score = random.randint(0, 130)
score.save()
return score
示例6: addscore
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def addscore(request, game_id):
if request.method == "POST":
form = ScoreForm(request.POST)
if form.is_valid():
score = Score()
score.score = form.cleaned_data.get("score", "0")
score.player = request.user
score.game = get_object_or_404(Game, pk=game_id)
score.date = datetime.now()
score.save()
return HttpResponseRedirect(reverse("ranking:index"))
else:
form = ScoreForm()
return render_to_response(
"ranking/addscore.html", {"form": form, "game_id": game_id}, context_instance=RequestContext(request)
)
示例7: match_edit
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def match_edit(request, match_id):
content = json.loads(request.body)
time = content['match_time']
users = content['users']
score_desc = content['score']
match = Match.objects.get(id=match_id)
match.match_time = time
match.users = [user['user_id'] for user in users]
score = None
if match.score:
score = match.score
score.score_desc = score_desc
score.save()
else:
if score_desc:
score = Score(score_desc=score_desc)
score.save()
if score:
match.score = score
match.save()
return JsonResponse({"success": "ok"})
示例8: initialiseScoring
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def initialiseScoring(request):
score = Score.objects(type='submitidea')
if not score:
score = Score()
score.type='submitidea'
score.value=100
score.save()
score = Score.objects(type='submitarticle')
if not score:
score = Score()
score.type='submitarticle'
score.value=80
score.save()
score = Score.objects(type='comment')
if not score:
score = Score()
score.type='comment'
score.value=50
score.save()
score = Score.objects(type='vote')
if not score:
score = Score()
score.type='vote'
score.value=40
score.save()
score = Score.objects(type='report')
if not score:
score = Score()
score.type='report'
score.value=20
score.save()
score = Score.objects(type='view')
if not score:
score = Score()
score.type='view'
score.value=10
score.save()
score = Score.objects(type='promotion')
if not score:
score = Score()
score.type='promotion'
score.value=80
score.save()
initialiseRatings()
return HttpResponseRedirect('/')
示例9: populate
# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def populate(self):
new_score = Score()
new_score.score = random.randint(1, 1234)
new_score.save()