我正在写一个django giftcardredeem,除了添加我的礼品卡后,一切都有效我无法保存价值
class GiftCardRedeem(FormView):
model = GiftCard
form_class = GiftCardCheck
template_name = 'site/redeem.html'
success_url = '/settings/redeem'
def form_valid(self, form):
MessageForm = form.save(commit=False)
one_entry = GiftCard.objects.get(code=form.cleaned_data['code'])
currentbal = self.request.user.userprofile.balance
totalbal = int(currentbal) + int(one_entry.worth)
print self.request.user.userprofile.balance
totalbal.save()
错误:
'int' object has no attribute 'save'
答案 0 :(得分:0)
.save()用于保存对象而不是对象/单个字段的一部分。而不是尝试保存值 - 将值添加到用户对象,然后保存。