-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
26 lines (21 loc) · 781 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# create a database
# books.db
# create a model
# title, author, date published, price
#
from sqlalchemy import (create_engine, Column, Integer, String, Date)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///books.db', echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Book(Base):
__tablename__ ='books'
id = Column(Integer, primary_key=True)
title = Column('Title', String)
author = Column('Author', String)
date_published = Column('Published', String)
price = Column('Price', Integer)
def __repr__(self):
return f'Title: {self.title} Author: {self.author} Published: {self.date_published} Price: {self.price}'