예제 #1
0
def update_post(request, post_id):
    note = get_object_or_404(Post, pk=post_id)

    if request.method == 'POST':
        newpost = NewPost(request.POST, instance=note)
        if newpost.is_valid():
            new = newpost.save(commit=False)
            new.auther = request.user
            new.save()
            return redirect('/')
    else:
        newpost = NewPost()
    context = {
        'title': 'تحرير تدوينة',
        'newpost': newpost,
        'post': note,
    }
    return render(request, 'app/update_post.html', context)
예제 #2
0
def new_post(request):

    if request.method == 'POST':
        newpost = NewPost(request.POST)
        if newpost.is_valid:
            new = newpost.save(commit=False)
            new.auther = request.user
            new.save()
            return redirect('/')

    else:
        newpost = NewPost()

    context = {
        'title': 'اضافة تدوينة جديدة',
        'newpost': newpost,
    }
    return render(request, 'app/new_post.html', context)