Example #1
0
def update(request, id):
    zixun = get_object_or_404(Zixun, pk=id)
    form = ZixunForm(instance=zixun)
    if request.method == "POST":
        form = ZixunForm(request.POST, instance=zixun)
        if form.is_valid():
            zixun = form.save(commit=False)
            zixun.typer = request.user
            zixun.save()
            return HttpResponseRedirect(reverse('zixun_list'))
    return render(request, 'jiaofu/create.html', {'form': form})
Example #2
0
def create(request):
    form = ZixunForm()
    if request.method == "POST":
        form = ZixunForm(request.POST)
        if form.is_valid():
            zixun = form.save(commit=False)
            zixun.typer = request.user
            zixun.year = datetime.today().year
            zixun.month = datetime.today().month
            zixun.save()
            return HttpResponseRedirect(reverse('zixun_list'))
    return render(request, 'jiaofu/create.html', {'form': form})