-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory_seeds.py
More file actions
41 lines (34 loc) · 821 Bytes
/
category_seeds.py
File metadata and controls
41 lines (34 loc) · 821 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
29
30
31
32
33
34
35
36
37
38
39
40
41
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.engine.url import URL
from models import Base, Category
DATABASE = {
'drivername': 'postgres',
'host': 'localhost',
'port': '5432',
'username': 'recipeapp',
'password': 'password',
'database': 'recipes'
}
# Connect to DB and create session
engine = create_engine(URL(**DATABASE))
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
category_names = [
'Quick & Easy',
'Slow Cooker',
'Low-Calorie',
'Salad',
'Soup',
'Appetizer',
'Vegetables',
'Meat',
'Seafood',
'Dessert'
]
for name in category_names:
category = Category(name=name)
session.add(category)
session.commit()
print("Added Categories into DB.")