def update(request, id): xinjin = get_object_or_404(XinjinDan, pk=id) form = XinjinDanForm(instance=xinjin) if request.method == "POST": form = XinjinDanForm(request.POST, instance=xinjin) if form.is_valid(): xinjin = form.save(commit=False) xinjin.typer = request.user xinjin.save() return HttpResponseRedirect(reverse('xinjin_list', args=[id])) return render(request, 'xinjin/create.html', {'form': form})
def create(request): form = XinjinDanForm() if request.method == "POST": form = XinjinDanForm(request.POST) if form.is_valid(): xinjin = form.save(commit=False) xinjin.bianhao = xinjin.bianhao.upper() xinjin.typer = request.user xinjin.year = datetime.today().year xinjin.month = datetime.today().month xinjin.save() return HttpResponseRedirect(reverse('xinjin_list', args=[xinjin.id])) return render(request, 'xinjin/create.html', {'form': form})