Add example of third party API
This commit is contained in:
@@ -5,11 +5,21 @@ from flask_script import Command
|
||||
|
||||
|
||||
from app import db
|
||||
from app.widget import Widget
|
||||
from app.fizz.fizzbaz import Fizzbaz
|
||||
from app.fizz.fizzbar import Fizzbar
|
||||
from app.other_api.doodad import Doodad
|
||||
from app.other_api.whatsit import Whatsit
|
||||
|
||||
|
||||
def seed_widgets():
|
||||
from app.widget import Widget
|
||||
widgets = [
|
||||
def seed_things():
|
||||
classes = [Widget, Fizzbaz, Fizzbar, Doodad, Whatsit]
|
||||
for klass in classes:
|
||||
seed_thing(klass)
|
||||
|
||||
|
||||
def seed_thing(cls):
|
||||
things = [
|
||||
{
|
||||
'name': 'Pizza Slicer',
|
||||
'purpose': 'Cut delicious pizza',
|
||||
@@ -23,7 +33,24 @@ def seed_widgets():
|
||||
'purpose': 'Bake delicious pizza',
|
||||
},
|
||||
]
|
||||
db.session.bulk_insert_mappings(Widget, widgets)
|
||||
db.session.bulk_insert_mappings(cls, things)
|
||||
# def seed_widgets():
|
||||
# from app.widget import Widget
|
||||
# widgets = [
|
||||
# {
|
||||
# 'name': 'Pizza Slicer',
|
||||
# 'purpose': 'Cut delicious pizza',
|
||||
# },
|
||||
# {
|
||||
# 'name': 'Rolling Pin',
|
||||
# 'purpose': 'Roll delicious pizza',
|
||||
# },
|
||||
# {
|
||||
# 'name': 'Pizza Oven',
|
||||
# 'purpose': 'Bake delicious pizza',
|
||||
# },
|
||||
# ]
|
||||
# db.session.bulk_insert_mappings(Widget, widgets)
|
||||
|
||||
|
||||
class SeedCommand(Command):
|
||||
@@ -35,6 +62,6 @@ class SeedCommand(Command):
|
||||
print('Dropping tables...')
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
seed_widgets()
|
||||
seed_things()
|
||||
db.session.commit()
|
||||
print('Widgets successfully seeded.')
|
||||
print('DB successfully seeded.')
|
||||
|
Reference in New Issue
Block a user