def create_view2(request): context = {} form = CerealForm2() context["form"] = form if request.method == "POST": form = SpeedModelForm2(request.POST, request.FILES) if form.is_valid(): print form.cleaned_data name = form.cleaned_data["title"] hctype = form.cleaned_data["hctype"] calories = form.cleaned_data["calories"] new_object = Cereal() new_object.name = name new_object.hctype = hctype new_object.calories = calories new_object.protein = protein new_object.fat = fat new_object.sodium = sodium new_object.fiber = fiber new_object.carbs = carbs new_object.sugars = sugars new_object.save() return HttpResponseRedirect("/list_view/") else: context["errors"] = form.errors return render_to_response("create_view2.html", context, context_instance=RequestContext(request))
print row['Sodium'] try: new_cereal.fiber = float(row['Dietary Fiber']) except Exception, e: print e print row['Dietary Fiber'] try: new_cereal.carbs = float(row['Carbs']) except Exception, e: print e print row['Carbs'] try: new_cereal.sugars = int(row['Sugars']) except Exception, e: print e print row['Sugars'] try: new_cereal.shelf = int(row['Display Shelf']) except Exception, e: print e print row['Display Shelf'] try: new_cereal.potassium = int(row['Potassium']) except Exception, e: print e print row['Potassium']