Last active
August 29, 2015 14:18
-
-
Save joefutrelle/fe4e361fc0f668e390bf to your computer and use it in GitHub Desktop.
SQLAlchemy ORM template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy import Column, String, Integer, Numeric | |
| from sqlalchemy.orm import backref, relationship | |
| Base = declarative_base() | |
| class Thing(Base): | |
| __tablename__ = 'things' | |
| id = Column(Integer, primary_key=True) | |
| name = Column(String) | |
| class Part(Base): | |
| __tablename__ = 'parts' | |
| id = Column(Integer, primary_key=True) | |
| name = Column(String) | |
| some_property = Column(Numeric) | |
| thing = relationship('Thing', | |
| backref=backref('parts', cascade='all, delete-orphan')) | |
| # ... | |
| engine = # ... get dbengine | |
| Base.metadata.create_all(engine) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment