Beispiel #1
0
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))
Beispiel #2
0
        manufacturer=row['Manufacturer'])
    # Old - new_maker.manufacturer = row['Manufacturer']
    new_maker.save()

    new_cereal = Cereal()
    new_cereal.manufacturer = new_maker
    new_cereal.name = row['Cereal Name']
    new_cereal.kind = row['Type']
    try:
        new_cereal.calories = int(row['Calories'])
    except Exception, e:
        print e
        print row['Calories']

    try:
        new_cereal.protein = int(row['Protein (g)'])
    except Exception, e:
        print e
        print row['Protein (g)']

    try:
        new_cereal.fat = int(row['Fat'])
    except Exception, e:
        print e
        print row['Fat']

    try:
        new_cereal.sodium = int(row['Sodium'])
    except Exception, e:
        print e
        print row['Sodium']