I have the following table using Flask-SQLAlchemy:
class Posts(db.Model):
id = db.Column(db.Integer, primary_key=True)
hashID = db.Column(db.String(6))
post = db.Column(db.String(500))
def __init__(self, post):
self.hashID = hashid.encode(self.id)
self.post = post
I want to create a hash using the autoincrementd ID field. I saw from other questions db.session.flush()
can be used however this will not work since I would preferably get the ID from the inside the init
.
The code above using self.id
will not work since self.id
returns a NoneType. Is there a way to get the ID that will be generated from inside the init
? Thanks.