Django使用自定义字段时不保存表单

时间:2014-04-07 13:26:12

标签: python django

我正在写一个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'

1 个答案:

答案 0 :(得分:0)

.save()用于保存对象而不是对象/单个字段的一部分。而不是尝试保存值 - 将值添加到用户对象,然后保存。