-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_setup.py
More file actions
28 lines (22 loc) · 888 Bytes
/
Copy pathdatabase_setup.py
File metadata and controls
28 lines (22 loc) · 888 Bytes
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
27
28
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from flask_login import UserMixin
Base = declarative_base()
class Item(Base):
__tablename__ = 'items'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(50), nullable=False)
category = Column(String(50))
description = Column(String(250))
image = Column(String(100))
user_id = Column(String(50), ForeignKey('users.id'))
class User(UserMixin, Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True, autoincrement=True)
username = Column(String(50), index=True)
pass_hash = Column(String(120))
status = Column(String(10))
engine = create_engine('sqlite:///catalog.db')
Base.metadata.create_all(engine)