示例#1
0
def publishers_new(request):
    if request.is_ajax():
        render_target = '_form.html'
    else:
        render_target = 'new.html'
    if request.method == 'POST':
        form = PublisherForm(request.POST)
        if form.is_valid():
            publisher = form.save()
            return redirect(publisher)
    else:
        form = PublisherForm()
    return render_to_response('publishers/%s' % render_target,
                              {'form': form, 'editing': False},
                              context_instance=RequestContext(request))
示例#2
0
def publishers_instance_edit(request, pk):
    publisher = Publisher.objects.get(pk=pk)
    if request.is_ajax():
        render_target = '_form.html'
    else:
        render_target = 'edit.html'
    if request.method == 'POST':
        form = PublisherForm(request.POST, instance=publisher)
        if form.is_valid():
            form.save()
            return redirect(publisher)
    else:
        form = PublisherForm(instance=publisher)
    return render_to_response('publishers/%s' % render_target,
                              {'object': publisher,
                               'form': form,
                               'editing': True},
                              context_instance=RequestContext(request))