-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a base class for SQL Alchemy models
- Loading branch information
1 parent
3a5ff70
commit af92c4e
Showing
3 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from sqlalchemy import Column, Integer | ||
from sqlalchemy.ext.declarative import ( | ||
declared_attr, declarative_base | ||
) | ||
|
||
|
||
class ModelBase(object): | ||
""" | ||
An augmented base class for SqlAlchemy models. | ||
""" | ||
|
||
@declared_attr | ||
def __tablename__(cls): | ||
""" | ||
Return the lowercase class name as the name of the table. | ||
""" | ||
return cls.__name__.lower() | ||
|
||
id = Column( | ||
Integer, | ||
primary_key=True, | ||
autoincrement=True | ||
) | ||
|
||
|
||
Base = declarative_base(cls=ModelBase) |
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