可能重复:
在表单提交时更新条目而不是保存新条目
我正在编辑表单并提交它,但它没有得到更新,而是存储在另一个条目中。
def searchinventory2(request, id = None):
print "sssssssssss", id
if id is not None:
task = Inventory.objects.get(id = id)
else:
pass
if request.method == 'POST': # If the form has been submitted...
print "dfdf"
form = Inventory_List(request.POST, request.FILES, instance=task)
print "hhhhhhhhhhhhh"
if form.is_valid():
print "ksjhjksfh"
form.save()
return task(request, 'Task #%s created successfully.' % (task.id))
else:
print "in else"
form = Inventory_List(instance = task)
return render_to_response("smartlogis/inventoryedit.html", {'form':form,})
我收到此错误:
local variable 'task' referenced before assignment