0
我有一個候選模型之一獲取關鍵的領域,而不是完整的密鑰
class Candidate(ndb.Model):
name = ndb.StringProperty()
phone = ndb.StringProperty()
location_name = ndb.StringProperty()
state = ndb.KeyProperty(kind=Setting)
型號叫做提交國家
class SubmissionState(ndb.Model):
name = ndb.StringProperty(required=True)
description = ndb.TextProperty()
模式設置,用來根據類別來處理設置,用戶選擇。所有這些工作正常。
這是views.py
。還有一個post方法,但我不確定這是否有必要。
class EditSubmission(webapp2.RedirectHandler):
def get(self):
candidateid = self.request.path.split('/')[-1]
candidate = Candidate._get_by_id(int(candidateid))
template_values = {'candidate': candidate, }
path = os.path.join(os.path.dirname(__file__), '../templates/edit_submission.html')
self.response.write(template.render(path, template_values))
這裏是模板的一部分:
<tr>
<th><label for="id_state">Submission State:</label></th>
<td><input id="id_state" type="text" name="state" value="{{ candidate.state.name }}"/></td>
</tr>
如果我做{{ candidate.state }}
我拿到鑰匙和所有的領域,但我不能因爲某些原因只得到名稱。我會怎麼做?
謝謝。
謝謝!這沒有竅門:) –