0

我想更新谷歌应用引擎数据存储中的现有实体。我知道 put() 要么创建/更新条目。但就我而言,它总是会创建一个新条目,为什么?...

我在views.py中的编辑功能

def edit(request,mykey):
   employee=Employeeprofile.get(mykey)
   data={
     'employee_name':employee.employee_name, 
     'employee_number': employee.employee_number,
     'employee_email': employee.employee_email,
     'employee_mobilenumber':employee.employee_mobilenumber,
     'employee_address': employee.employee_address
   }

   form= Employeeprofileform(data)
   import pdb;pdb.set_trace()
   if request.POST:
       form= Employeeprofileform(request.POST)
           if form.is_valid():          
               employee.employee_name =form.cleaned_data['employee_name']
               employee.employee_number=form.cleaned_data['employee_number']
               employee.employee_email = form.cleaned_data['employee_email']
               employee.employee_mobilenumber= form.cleaned_data['employee_mobilenumber']
               employee.employee_address = form.cleaned_data['employee_address']
               employee.put(mykey)
               return HttpResponseRedirect("/listallemployees/")
            else:
               return render_to_response('main/edit.html', {'form': form,'mykey':mykey})

      else:
    return render_to_response('main/edit.html', {'form': form,'mykey':mykey})

为什么?...

我需要用相同的密钥更新数据。我正在使用 django1.2

4

0 回答 0