Flask SQLAlchemy One-on-one, a one-to-many approach to practice _python

Source: Internet
Author: User
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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.