我正在使用gae-boilerplate(webapp2和jinja2)。我的模型看起来像这样:
class Location(ndb.Model):
x = ndb.FloatProperty()
y = ndb.FloatProperty()
class Criterium(polymodel.PolyModel):
name = ndb.StringProperty(required=True)
user = ndb.KeyProperty(kind='User')
priority = ndb.IntegerProperty(required=True)
class Work(Criterium):
location = ndb.StructuredProperty(Location)
class Friend(Criterium):
location = ndb.StructuredProperty(Location)
我有一张包含Criterium模型所有记录的表格。我想在那里添加一个删除链接,但我不知道用什么参数传递它以引用特定的实体。我的处理程序如下所示:
def get(self):
criteria = Work.query().order(-Criterium.priority, Criterium.name)
self.view.list_columns = [('name', 'Name'),
('priority', 'Priority'),
('className', 'Type')]
self.view.criteria = criteria
self.view.count = criteria.count()
params={}
self.render_template('list.html', **params)
看起来像一个简单的问题,但一整天都在苦苦挣扎......提前谢谢!
答案 0 :(得分:1)
对象的id
怎么样?
这就是Criterium
模型中该对象的唯一标识符。
:
for criterum in criteria:
criterum.key.id()
答案 1 :(得分:0)
见下面的例子
来自google.appengine.ext import ndb
类User(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add = True)
firstName = ndb.StringProperty(required = True)
lastName = ndb.StringProperty(required = True)
email = ndb.StringProperty(required = True)
pwHash = ndb.StringProperty(required = True)
@classmethod
def byEmail(cls, email):
u = cls.query(cls.email == email).get()
return u
@classmethod
def register(cls, firstname, lastname, email, password):
pwhash = utils.makePwHash(email, password)
return User(firstName=firstname,
lastName=lastname,
email=email,
pwHash=pwhash)
@classmethod
def login(cls, email, password):
u = User.byEmail(email)
if u and utils.validPW(email, password, u.pwHash):
return u