Reputation: 65
I am using gae-boilerplate (webapp2 and jinja2). My model looks like this:
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)
I have a table with all records from the Criterium model. I would like to add a delete link there, but I don't know what argument to pass with it in order to refer to the specific entity. My handler looks like this:
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)
Seems like a simple problem, but have been struggling all day... Thanks in advance!
Upvotes: 1
Views: 389
Reputation: 1
see example below
from google.appengine.ext import ndb
class 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
Upvotes: 0
Reputation: 7158
what about the id
of the object?
thats the unique identifier for that object within the Criterium
model.
when looping over the criteria entities:
for criterum in criteria:
criterum.key.id()
Upvotes: 1