I'm working on a project using Python(3.7) and Flask. I'm transferring an application from Google App Engine Webapp2 in which models have been implemented using NDB, so I need to convert these models into SqlAlchemy models. I found a make_key
method in models classes which I don't know what they exactly, so how can I convert it to SqlAlchemy models.
Here are some examples of models from NDB
:
class Groupvalue(ndb.Model):
"""A main model for representing an individual Guestbook entry."""
value = ndb.StringProperty()
rank = ndb.IntegerProperty(default=1)
username = ndb.StringProperty()
@classmethod
def make_key(cls, isbn):
return ndb.Key(cls, isbn)
class LoxonValues(ndb.Model):
"""A main model for representing an individual Guestbook entry."""
value = ndb.StringProperty()
score = ndb.StringProperty()
rank = ndb.IntegerProperty(default=1)
username = ndb.StringProperty()
group = ndb.StringProperty(default='notingroup')
date = ndb.DateTimeProperty(auto_now_add=True)
@classmethod
def make_key(cls, isbn):
return ndb.Key(cls, isbn)
and Here's how I have transferred these models into Python-SqlAlchemy:
class Groupvalue(db.Model):
value = db.Column(db.String())
rank = db.Column(db.Integer(default=1))
username = db.Column(db.String())
class LoxonValues(db.Model):
value = db.Column(db.String())
score = db.Column(db.String())
rank = db.Column(db.Integer(default=1))
username = db.Column(db.String())
group = db.Column(db.String(default='notingroup'))
date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
I'm confused about the make_key
method which has been utilized into NDB
models, what's the equivalent of this in SqlAlchemy?