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