感谢您的小费。也许我可以编辑它以更好地解释它......
我正在为 Google App Engine 编写一个应用程序,我想在其中执行 GQL 查询以获取已提交的每种类型的所有评估。我希望允许用户单击链接来编辑每个单独的评估,然后提交更改。这是我发现的最好的方法......
class EvaluationApproval(webapp.RequestHandler):
def get(self):
#search for unapproved general evaluations
query = db.GqlQuery("SELECT * FROM GeneralAssessmentReport WHERE Approved = False")
if query.count() != 0:
for item in query:
#create a link to edit that item
self.response.out.write('<a href="generalFromApprove?key=%s">%s</a>' % (item.key(), item.Name))
#do this for each type of evaluation...
query = db.GqlQuery("SELECT * FROM HeadNeck WHERE Approved = False")
if query.count() != 0:
for item in query:
self.response.out.write('<a href="headNeckApprove?key=%s">%s</a>' % (item.key(), item.Name))
query = db.GqlQuery("SELECT * FROM lowerExtremity WHERE Approved = False")
if query.count() != 0:
for item in query:
self.response.out.write('<a href="lowerApprove?key=%s">%s</a>' % (item.key(), item.Name))
所以,当用户点击他们被定向到的链接时......
class GeneralFormApprove(webapp.RequestHandler):
def get(self):
# get the correct evaluation to approve
key = self.request.get('key')
item = GeneralAssessmentReport.get(key)
#write out the form with key in the form action!
self.response.out.write('<form method="POST" action="/generalFormApprove?key=%s">' % key)
self.response.out.write(GeneralAssessmentReportForm(instance=item))
def post(self):
# get the key once more
key = self.request.get('key')
data = GeneralAssessmentReportForm(data=self.request.POST,instance=GeneralAssessmentReport.get(key))
if data.is_valid():
# save the edited evaluation
entity = data.save(commit=False)
entity.put()
然后为每种类型的评估创建一个 WhatFormApprove 类。这有意义吗?您还有其他想法可以实现吗?