def add_test_data_to_db(): """Adds test data to the database, create_db must be called first. """ ships = [ {'name': 'Achilles', 'sh_class': 'Leander', 'type': 'Light Cruiser', 'country': 'NZL', 'build_date': '1000-01-01'}, {'name': 'Admiral Graf Spee', 'sh_class': 'Deutschland', 'type': 'Heavy Cruiser', 'country': 'GER', 'build_date': '1000-01-01'}, {'name': 'Cumberland', 'sh_class': 'County-Kent', 'type': 'Heavy Cruiser', 'country': 'UK', 'build_date': '1000-01-01'}, {'name': 'Exeter', 'sh_class': 'York', 'type': 'Heavy Cruiser', 'country': 'UK', 'build_date': '1000-01-01'}, {'name': 'Ajax', 'sh_class': 'Leander', 'type': 'Light Cruiser', 'country': 'UK', 'build_date': '1000-01-01'} ] battles = [ {'name': 'River Platte', 'conflict': 'WWII', 'date': '1939-12-13'}, {'name': 'Battle of the Java Sea', 'conflict': 'WWII', 'date': '1942-02-27'} ] with models.database.atomic(): Ship.insert_many(ships).execute() Battle.insert_many(battles).execute() river_platte = Battle.select().where(Battle.name == 'River Platte').get() java_sea = Battle.select().where(Battle.name == 'Battle of the Java Sea').get() for ship in Ship.select(): if ship.name == 'Ajax': ShipBattle.create(ship=ship, battle=java_sea) ShipBattle.create(ship=ship, battle=river_platte) models.database.close()