2
感谢您的提示。也许我可以编辑这个来解释它更好一点...如何编辑在Google App Engine中使用Django表单提交的信息
我在写一个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()
,然后有一个WhateverFormApprove每类评估的类别。这是否有意义,你有任何其他想法来实现这一点?
我不知道我理解你的问题,但在全局变量存储状态是一个坏主意。这是因为后续请求可以通过完全不同的进程来处理。 为了更好地解决这个问题,您应该从您发布的代码中删除不重要的细节。人们通常不想回答他们必须阅读整个应用程序的问题。尝试直接和具体。 – allyourcode 2012-05-26 07:43:35