Exemplo n.º 1
0
Arquivo: views.py Projeto: zako16/gag
def create_post(request):
    if request.user.is_staff:
        form = PostsForm(request.POST or None, request.FILES or None)
        if form.is_valid():
            form.save()
            return redirect('/index')
        return render(request, 'posts/create_post.html', {'form': form})
    return redirect('/error/')
Exemplo n.º 2
0
Arquivo: views.py Projeto: zako16/gag
def edit_post(request, post_id):
    if request.user.is_staff:
        post = Posts.objects.get(id=post_id)
        form = PostsForm(request.POST or None, request.FILES or None, instance=post)
        if form.is_valid():
            form.save()
            return redirect('/index')
        return render(request, 'posts/create_post.html', {'form': form})
    return redirect('/error/')