Beispiel #1
0
def create_view2(request):

    context = {}

    form = CerealForm2()
    context['form'] = form

    if request.method == 'POST':
        form = CerealForm2(request.POST, request.FILES)

        if form.is_valid():

            print form.cleaned_data

            title = form.cleaned_data['title']
            info = form.cleaned_data['info']
            # image = form.cleaned_data['image']

            new_object = Cereal()

            new_object.title = title
            new_object.info = info
            # new_object.image = image

            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
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 #3
0
        print row['Display Shelf']

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

    try:
        new_cereal.vitamins = int(row['Vitamins and Minerals'])
    except Exception, e:
        print e
        print row['Vitamins and Minerals']

    try:
        new_cereal.serving_size_weight = float(row['Serving Size Weight'])
    except Exception, e:
        print e
        print row['Serving Size Weight']

    try:
        new_cereal.cups_per_serving = float(row['Cups per Serving'])
    except Exception, e:
        print e
        print row['Cups per Serving']

    new_cereal.save()


csv_file.close()