【发布时间】:2021-09-10 02:21:30
【问题描述】:
我想知道如何将数据添加到代码中ins.save 之后的 Django 整数字段。例如,如果捐赠字段等于3,在ins.save之后,我想给它加1,因此它等于4。我的代码在下面。
捐赠观点:
def donate(request):
if request.method == "POST":
title = request.POST['donationtitle']
phonenumber = request.POST['phonenumber']
category = request.POST['category']
quantity = request.POST['quantity']
location = request.POST['location']
description = request.POST['description']
ins = Donation(title = title, phonenumber = phonenumber, category = category, quantity = quantity, location = location, description = description, user=request.user, )
ins.save()
return render(request,'donate.html')
【问题讨论】:
-
你不需要那个字段,你可以简单地查询来计算那个数字。
-
我该怎么做?
-
你能展示一下你的
Donation模特吗? -
是的,更新我的问题
-
更新,捐赠模型从 HTML 表单中获取数据,提交数据后,我想将数据添加到 UserDetail 模型中。
标签: python html css django django-models