Flask-sqlalchemy Installation and table operation please refer to here.
Copy Code code as follows:
# Role Table
Class role (db. Model):
Id=db. Column (db. Integer,primary_key=true)
Name=db. Column (db. String (80))
# Roletype Table
Class Role_type (db. Model):
Query_class=common_list_name_query
Id=db. Column (db. Integer,primary_key=true)
Name=db. Column (db. String (120))
One
You just need to change the definition in the attribute.
Copy Code code as follows:
# Role Table
Class role (db. Model):
Role_type_id=db. Column (db. Integer,db. ForeignKey (' role_type.id '))
Role=db.relationship (' role ', backref= ' Role_type ', lazy= ' dynamic ', uselist=false)
A pair of many
Copy Code code as follows:
# A couple needs to fill in the two-table bucket of the relationship between
Class role (db. Model):
Role_type_id=db. Column (db. Integer,db. ForeignKey (' role_type.id '))
Class Role_type (db. Model):
Roles=db.relationship (' role ', backref= ' Role_type ', lazy= ' dynamic ')
Specific parameters can refer to the following documents:
http://flask.pocoo.org/docs/patterns/sqlalchemy/
http://packages.python.org/Flask-SQLAlchemy/