コード例 #1
0
ファイル: manage.py プロジェクト: nodes11/Drinks
def seed_commands(data_list, column):
    for data in data_list:
        data_column = column(data)
        try:
            db_session.add(data_column)
            db_session.commit()
        except:
            db_session.rollback()
    return
コード例 #2
0
ファイル: manage.py プロジェクト: nodes11/Drinks
def seed_brands_associations():
    """Seeds the brands and country."""
    associations = seed_brand_association_data()
    countries = Country.query.all()
    brands = Brand.query.all()

    country_name_id = {}
    for country in countries:
        country_name_id[country.name] = country.id

    for brand in brands:

        brand_name = brand.name
        brand_id = brand.id

        country_name = associations[brand_name]
        country_id = country_name_id[country_name]

        try:
            brand_update = Brand.query.filter_by(id=brand_id).first()
            brand_update.country_id = country_id
            db_session.commit()
        except:
            db_session.rollback()