Exemplo n.º 1
0
def games_instance_edit(request, pk):
    game = Game.objects.get(pk=pk)
    if request.is_ajax():
        render_target = '_form.html'
    else:
        render_target = 'edit.html'
    if request.method == 'POST':
        form = GameForm(request.POST, instance=game)
        if form.is_valid():
            form.save()
            return redirect(game)
    else:
        form = GameForm(instance=game)
    return render_to_response('games/%s' % render_target,
                              {'object': game,
                               'form': form,
                               'editing': True},
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def games_new(request):
    if request.is_ajax():
        render_target = '_form.html'
    else:
        render_target = 'new.html'
    if request.method == 'POST':
        form = GameForm(request.POST)
        if form.is_valid():
            game = form.save()
            return redirect(game)
    else:
        form = GameForm()
    return render_to_response('games/%s' % render_target,
                              {'form': form, 'editing': False},
                              context_instance=RequestContext(request))