== 'POST': 12 action = request.POST['action'].lower() 13 todo_list_form = TodoListForm(data=request.POST, todos=todos) 14 if todo_list_form.is_valid(): 15 selected = Todo.objects.filter( 16 id__in=todo_list_form.cleaned_data) 17 actions = {'done': lambda items: items.update(is_done=True), 18 'delete': lambda items: items.delete()} 19 actions.get(action)(selected) 20 messages.add_message(request, messages.SUCCESS, 21 'Items has been updated.') 22 else: 23 messages.add_message(request, messages.ERROR, 24 ''.join(todo_list_form.non_field_errors())) 25 return redirect('home') 26 else: 27 todo_form = TodoForm() 28 todo_list_form = TodoListForm(todos=todos) 29 context = {'todo_list_form': todo_list_form, 'todo_form': todo_form} 30 return render_to_response('todo/home.html', context, 31 RequestContext(request)) todo/views.py