python - How do I call a class integer and add increase it's value? -
we have class in our models.py:
class score(model.model): score = models.integerfield()
we want phone call score object , update within of our views.py, when reply correct:
def answer(request, level_id): # next 3 lines working us. o = level.objects.get(id=level_id) guess = request.get.get('guess', '').strip() right = o.answers.filter(value__iexact=guess).exists() b = score.objects.get('score') b.score += o.points b.save()
we still haven't made b.score += o.points run using if
statement, because first wanted see if can update b.score.
class level(model.models): points = models.integerfield("point value')
the error is:
valueerror @ /answer/1 many values unpack
try this!
def answer(request, level_id): # next 3 lines working us. o = level.objects.get(id=level_id) guess = request.get.get('guess', '').strip() right = o.answers.filter(value__iexact=guess).exists() b = score.objects.get(score) b.score += int(o.points) b.save()
you missing on saving object, when update it.
b.save() # should save
python django
No comments:
Post a Comment