def New(request): template_file = "shift-new.html" context = RequestContext(request) form = ShiftForm(request.POST or None, request.FILES or None) if form.is_valid(): mymodel = form.save() msg = u"Shift successfully created" messages.add_message(request, messages.SUCCESS, msg) return redirect("shift:home") params = { 'form': form, } return render_to_response ( template_file, params, context_instance = context )
def Edit(request,shift_id): template_file = "shift-edit.html" context = RequestContext(request) obj = Shift.objects.get(pk=shift_id) form = ShiftForm(request.POST or None, request.FILES or None,instance=obj) if form.is_valid(): mymodel = form.save() msg = u"shift saved successfully" messages.add_message(request, messages.SUCCESS, msg) return redirect("shift:home") params = { 'form': form, 'shift_id': shift_id, } return render_to_response ( template_file, params, context_instance = context )