How to programmatically handle a user before committing to database in Flask-User? -
simply put i'm creating user
in flask-user want programmatically determine fields when user
created. namely want assign user
uuid4.
i've started following template: flask-user-starter-app
i've defined field need in models.py
:
class user(db.model, usermixin): __tablename__ = 'users' id = db.column(db.integer, primary_key=true) ... public_uuid = db.column(db.string(32), nullable=false, unique=true) ...
however seem unable find place can intercept user object , set user.public_uuid = uuid.uuid4().hex
i've tried declaring in form (though figured beforehand wouldn't work): class myregisterform(registerform): public_uuid = uuid.uuid4().hex
so end error public_uuid null
when writing database.
where can handle user object before it's committed db?
you can specify default
parameter of public_uuid
column function.
def generate_uuid(): return uuid.uuid4().hex class user(db.model, usermixin): # ... public_uuid = db.column(db.string(32), nullable=false, unique=true, default=generate_uuid)
Comments
Post a Comment