Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
guestbook_demo/guestbook_demo/db.py /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (19 sloc)
870 Bytes
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
| import datetime | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import scoped_session, sessionmaker | |
| from sqlalchemy.schema import Column | |
| from sqlalchemy.types import DateTime, Integer, Unicode | |
| engine = create_engine('postgresql:///guestbook_demo') | |
| session = scoped_session(sessionmaker(bind=engine, autoflush=False)) | |
| Base = declarative_base(bind=engine) | |
| ### Yonder tables | |
| class GuestbookEntry(Base): | |
| __tablename__ = 'guestbook_entries' | |
| id = Column(Integer, primary_key=True, nullable=False) | |
| timestamp = Column(DateTime, nullable=False, index=True) | |
| name = Column(Unicode, nullable=False) | |
| message = Column(Unicode, nullable=False) | |
| def __init__(self, **kwargs): | |
| kwargs.setdefault('timestamp', datetime.utcnow()) | |
| super(GuestbookEntry, self).__init__(**kwargs) |