def test(request): berg = Beverage(name='Ultimate Frozen Strawberry Margarita', description='A near perfect strawberry margarita with frozen strawberries and limeade concentrate.', image='http://images.media-allrecipes.com/userphotos/250x250/00/23/47/234705.jpg', recipe={'tequila':170, 'triple sec':56, 'frozen sliced strawberries':226}, tags=['sweet', 'cool']) berg.put() return HttpResponse("Hello, world. You're at the beverage index.")
def add_beverage(request): if request.method != 'POST': return HttpResponse("should be post") if 'name' not in request.POST: return HttpResponse("name field is empty") if 'recipe' not in request.POST: return HttpResponse("name field is empty") berg = Beverage(name = request.POST['name'], recipe = json.loads(request.POST['recipe'])) if 'tags' in request.POST: tags = request.POST['tags'] berg.tags = [x.strip() for x in tags.split(",")] if 'description' in request.POST: berg.description = request.POST['description'] berg.put() return HttpResponse('completed')