+ -
当前位置:首页 → 问答吧 → Python更新方法怎么写?

Python更新方法怎么写?

时间:2010-12-16

来源:互联网

class PhotoLib_PhotoUpdate(PublicPage):
  def get(self):
  indexNo = self.request.get('indexNo')#图片索引号  
  photoLib_Photos = db.GqlQuery("SELECT * FROM PhotoLib_Photo WHERE indexNo=:1",string.atoi(indexNo))
  template_values = {'photoLib_Photos':photoLib_Photos,}
  self.render('html/photoLidManage/photoLib_PhotoList.html',template_values)#本地上运行用这个
  def post(self):
  photoLibCode = self.request.get('photoLibCode')#图库编号
  photoCode = self.request.get('photoCode')#图片编号
  indexNo = self.request.get('indexNo')#图片索引号
  photoLib_Photos = db.GqlQuery("SELECT * FROM PhotoLib_Photo WHERE indexNo=:1",string.atoi(indexNo))
  if photoLib_Photos:
  for photoLib_Photo in photoLib_Photos:
  photoLib_Photo.status = self.request.get('status')#图片状态
  photoLib_Photo.lastUpdateTime = datetime.datetime.now()#最后更新时间
  db.put(photoLib_Photo)
  self.redirect('/photoLib_PhotoList?photoLibCode=%s' %indexNo)

上面上我写的一个更新图片状态的方法,也是运行后没报错也没更新成功!
下面是页面的代码:
<table id="TableNew" class="t1" align="center" width="100%" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse" onMouseOver="cells_color()" onMouseOut="cells_color()">
<thead>
<th>图片库编号</th>
  <th>图片编号</th>
<th>索引号</th>
<th>图片状态</th>
<th>上次更新时间</th>
</thead>
{% for photoLib_Photo in photoLib_Photos %}
{% if photoLib_Photo.photoLibCode %}
  <form id="{{photoLib_Photo.photoLibCode}}" method="post" action="/PhotoLib_PhotoUpdate">
<tr style="cursor:hand" onClick="SelectTR(this)">
<td>{{photoLib_Photo.photoLibCode}}</td>
<td>{{photoLib_Photo.photoCode}}</td>
<td>{{photoLib_Photo.indexNo}}</td>
   
  <td><select name="status">
<option value="1" {%ifequal photoLib_Photo.status '1'%} selected {%endifequal%}>名字被更改</option>
<option value="2" {%ifequal photoLib_Photo.status '2'%} selected {%endifequal%}> 已 删 除 </option>
<option value="3" {%ifequal photoLib_Photo.status '3'%} selected {%endifequal%}> 增 加 </option>
  </select>  
</td>
<td>{{photoLib_Photo.lastUpdateTime}}<input name="lastUpdateTime" type="hidden" value="{{photoLib_Photo.lastUpdateTime}}"></td>
  <input name="index" type="hidden" value="{{index}}">
  <td><input type="button" onClick="formSubmit(this);" value="确定"></td>
  <td><input name="indexNo" type="radio" id="box" value="{{photoLib_Photo.indexNo}}" >
  <input name="photoLibCode" style="visibility:hidden; display:none" type="radio" id="code" value="{{photoLib_Photo.photoLibCode}}" ></td>
</tr>
  </form>
{%endif%}
{%endfor%}
</table>
请各位大虾帮我看一下,是不是我什么地方写错了!

作者: xieyingan   发布时间: 2010-12-16

忘了说一下,我的目的是这样子的:
点一下“确定”按钮之后就更新当前行!
跳回这个页面(等于点确定后不用跳转,只要刷新一下当前列表就可以了!)

作者: xieyingan   发布时间: 2010-12-16

你的更新数据库的代码是什么?db.put吗?首先你确认这段代码执行了,然后确认下这是正确的方法。

作者: iambic   发布时间: 2010-12-16

引用 2 楼 iambic 的回复:
你的更新数据库的代码是什么?db.put吗?首先你确认这段代码执行了,然后确认下这是正确的方法。
更新方法就是put(),代码也应该有执行吧,要不然我写不好它怎么会出错。

作者: xieyingan   发布时间: 2010-12-16