Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomBase(object):
- # Generate __tablename__ automatically
- @declared_attr
- def __tablename__(cls):
- return cls.__name__.lower()
- # Every class has an id field, by default Integer
- @declared_attr
- def id(cls):
- for base in cls.__mro__[1:-1]:
- if getattr(base, '__table__', None) is not None:
- type = ForeignKey(base.id)
- break
- else:
- type = Integer
- return Column(type, primary_key=True)
- Base = declarative_base(cls=CustomBase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement