Last active
January 2, 2021 06:00
-
-
Save kevinlondon/35a1d30e36d4f4ee47ec8c9975871829 to your computer and use it in GitHub Desktop.
This file contains 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.orm import declarative_base, scoped_session, sessionmaker | |
from sqlalchemy.ext.declarative.base import _declarative_constructor | |
from sqlalchemy import Column, Integer, ForeignKey, create_engine | |
engine = create_engine(# engine init code here) | |
session = scoped_session(sessionmaker(bind=engine)) | |
class CustomBase(object): | |
def __init__(self, **kwargs): | |
_declarative_constructor(self, **kwargs) | |
session.add(self) | |
Entity = declarative_base(cls=CustomBase, constructor=CustomBase.__init__) | |
class Item(Entity): | |
id = Column(Integer, primary_key=True) | |
type_id = Column(ForeignKey('item_type.id'), Integer) | |
class ItemType(Entity): | |
id = Column(Integer, primary_key=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment