google app engine - Getting one of the key's fields instead of the full key -


i have candidate model

class candidate(ndb.model):     name = ndb.stringproperty()     phone = ndb.stringproperty()     location_name = ndb.stringproperty()     state = ndb.keyproperty(kind=setting) 

model called submission state

class submissionstate(ndb.model):     name = ndb.stringproperty(required=true)     description = ndb.textproperty() 

model setting used handle settings based on category user selected. of works fine.

here views.py. there post method, not sure if that's necessary here.

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)) 

here template part:

    <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> 

if {{ candidate.state }} key , of fields, can not name reason. how that?

thanks.

candidate.state key points submissionstate. app needs make request datastore fetch submissionstate entity, this:

state_name = candidate.state.get().name 

you can perform get() in handler, , add state_name template values it's available within template.


Comments