Ejemplo n.º 1
0
Archivo: views.py Proyecto: txm/potato
def admin_home(request):

    if request.method == 'POST':
        form = BlogForm(data=request.POST)
        if form.is_valid():
            blog = form.save()
            form = BlogForm()
            tweet(request, blog)

    else:
        form = BlogForm()

    blogs = Blog.objects.all()

    return render_to_response('admin_home.html', {
        'form': form,
        'blogs': blogs,
    }, context_instance=RequestContext(request))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: txm/potato
def admin_edit(request):

    if request.method == 'POST':       # If the form has been submitted...
        blog = Blog.objects.get(id=request.GET['id'])
        form = BlogForm(instance=blog,data=request.POST)
        if form.is_valid():            # All validation rules pass
            form.save()
            return HttpResponseRedirect('/admin/') # Redirect after POST

    elif request.GET.has_key('id'):
        blog = Blog.objects.get(id=request.GET['id'])
        form = BlogForm(instance=blog)
        blogs = Blog.objects.all()
        return render_to_response('admin_home.html', {
            'form': form,
            'blogs': blogs,
            'id': request.GET['id'],
        }, context_instance=RequestContext(request))

    else:
        return HttpResponseRedirect('/admin/') # Redirect after POST