def post(self): beer_name = self.beer_args['beer_name'] description = self.beer_args['description'] harmonization = self.beer_args['harmonization'] color = self.beer_args['color'] alcohol = self.beer_args['alcohol'] temperature = self.beer_args['temperature'] beer_ingredients = self.ingredients_args['ingredients'] beers = BeerModel( beer_name=beer_name.lower(), description=description, harmonization=harmonization, color=color, alcohol=alcohol, temperature=temperature ) beers.save() beer_id = beers.id for ingredient in beer_ingredients['names']: ingredients = IngredientsModel( ingredient_name=ingredient, beer_id=beer_id ) ingredients.save() return resp_successfully('Beer', 201)
def populate_beers(amount): for r in range(0, amount): beer = Beer(beer_name=beers_data[r]['beer_name'], description=beers_data[r]['description'], color=beers_data[r]['color'], alcohol=beers_data[r]['alcohol'], temperature=beers_data[r]['temperature'], harmonization=beers_data[r]['harmonization']) beer.save() beer_id = beer.id for ingredient in ingredients_data[r]['ingredients'][0]['names']: ingredients = BeerIngredients(ingredient_name=ingredient, beer_id=beer_id) ingredients.save()