I am using Appengine 1.6.5, accessing a NDB model class property from a jinja2 template I got None, instead I got the right result accessing the same propery on a loop. to explain the problem I post some code
--- Models ---
class Vehicles(ndb.Model):
registration = ndb.StringProperty()
brand = ndb.StringProperty()
model = ndb.StringProperty()
cost = ndb.FloatProperty()
km_cost = ndb.FloatProperty()
viacard = ndb.StringProperty()
telepass = ndb.StringProperty()
class Employees(ndb.Model):
user_id = ndb.StringProperty()
name = ndb.StringProperty()
surname = ndb.StringProperty()
email = ndb.StringProperty()
job = ndb.StringProperty()
credit_card = ndb.StringProperty()
cc_expiry_date = ndb.StringProperty()
vehicle = ndb.KeyProperty(kind=Vehicles)
last_login = ndb.DateTimeProperty(auto_now=True)
last_activity = ndb.DateTimeProperty(auto_now=True)
@property
def vehicle_registration(self):
return Key(self.vehicle.kind(),int(self.vehicle.id())).get().registration
--- Handlers --- This i only a part of the handler
class BaseHandler(webapp2.RequestHandler):
@webapp2.cached_property
def jinja2(self):
return jinja2.get_jinja2(app=self.app)
def render_template(self, filename, **kwargs):
self.response.write(self.jinja2.render_template(filename, **kwargs))
class EmployeesHandler(BaseHandler):
@login_required
def get(self,**kwargs):
user = users.get_current_user()
company = models.Company.query().fetch(1)
employees = models.Employees.query().fetch()
vehicles = models.Vehicles.query().fetch()
params = {
"nickname" : user.nickname(),
"company" : company,
"employees" : employees,
"vehicles" : vehicles
}
return self.render_template('employee.html', **params)
--- Template --- This is a part of the templte
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>Email</th>
<th>Ruolo</th>
<th>Carta di credito</th>
<th>Scadenza</th>
<th>Auto</th>
<th>Ultimo accesso</th>
<th>Ultimo movimento</th>
</tr>
</thead>
<tbody>
{% for emp in employees %}
<tr>
<td>{{ emp.name }}</td>
<td>{{ emp.surname }}</td>
<td>{{ emp.email }}</td>
<td>{{ emp.job }}</td>
<td>{{ emp.credit_card }}</td>
<td>{{ emp.cc_expiry_date }}</td>
<td>({{ emp.vehicle.vehicle_registration }})</td>
<td>{{ emp.last_login }}</td>
<td>{{ emp.last_activity }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Can anyone tell me the right way to get the employ's car's registration number? Thank's in advance
Regards, Roberto