-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
43 lines (27 loc) · 852 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from sqlalchemy import create_engine, Column, Integer, String, Boolean
from sqlalchemy.engine import URL
from sqlalchemy.orm import declarative_base, sessionmaker
from starlette.applications import Starlette
from starlette_admin.contrib.sqla import Admin, ModelView
url = URL.create(
drivername="postgresql",
username="postgres",
password="Mahima",
host="localhost",
database="zaltan",
port=5432
)
engine = create_engine(url)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Course(Base):
__tablename__ = "courses"
id = Column(Integer, primary_key=True)
title = Column(String)
price = Column(Integer)
Base.metadata.create_all(engine)
app = Starlette()
admin = Admin(engine, title="BookStore")
admin.add_view(ModelView(Course,session))
admin.mount_to(app)