示例#1
0
def new_lunch_template(request,curr_date):
    if request.method == 'POST':
        form = LunchForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/lunch/')
    else:
        new_lunch = Lunch()
        new_lunch.date = curr_date
        new_lunch.time = "13:00"
        form = LunchForm(instance=new_lunch)
    return render_to_response('new_lunch.html', {'form': form})
示例#2
0
def edit_lunch_template(request,edit_pk):
    if  edit_pk == None:
        curr_lunch = Lunch()
    else:
        curr_lunch = Lunch.objects.get(pk=edit_pk)
        
    if request.method == 'POST':
        form = LunchForm(request.POST, instance=curr_lunch)
        if form.is_valid():
            edited_lunch = form.save(commit=False)            
            edited_lunch.save(force_update=True,force_insert=False)
            return HttpResponseRedirect('/lunch/')
    else:
        form = LunchForm(instance=curr_lunch)
    return render_to_response('new_lunch.html', {'form': form})