1

我正在使用 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)

我有一张包含标准模型中所有记录的表。我想在那里添加一个删除链接,但我不知道要传递什么参数来引用特定实体。我的处理程序如下所示:

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)

似乎是一个简单的问题,但是整天都在苦苦挣扎……在此先感谢!

4

2 回答 2

1

id对象的呢?那是模型
中该对象的唯一标识符。Criterium

循环条件实体时:

for criterum in criteria:
    criterum.key.id()
于 2013-03-19T16:03:04.687 回答
0

见下面的例子

从 google.appengine.ext 导入 ndb

类用户(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
于 2013-03-19T20:04:43.090 回答