예제 #1
0
def createPost(request):
    form = PostForm()
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect("home-url")
    data = {'form': form}
    return render(request, template_name='blog/createPost.html', context=data)
예제 #2
0
def post_edit(request, post_id):
	post = get_object_or_404(Post, id=post_id)
	if request.method == "POST":
		form = PostForm(request.POST, instance=post)
		if form.is_valid():
			form.save()
			return redirect('/index/')
	else:
		form = PostForm(instance=post)
	return render(request, 'post_add.html', {'form' : form})
예제 #3
0
파일: views.py 프로젝트: snripa/WildWorld
def post_edit(request, post_id):
    post = get_object_or_404(Post, id=post_id)
    if request.method == "POST":
        form = PostForm(request.POST, instance=post)
        if form.is_valid():
            form.save()
            return redirect('/index/')
    else:
        form = PostForm(instance=post)
    return render(request, 'post_add.html', {'form': form})
예제 #4
0
def create(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        # form 인스턴스를 생성하고 요청(request.POST)에 의한 data를 넣는다 .
        if form.is_valid():
            form.save()
            return redirect('/blog/index/', pk=pk)
    else:
        form = PostForm()
    return render(request, 'blog/create.html', {'form': form})
예제 #5
0
def post_add(request):

    if request.method == 'POST':

        form = PostForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('post_add')
    else:
        form = PostForm()
    return render(request, 'post_add.html', {'form': form})
예제 #6
0
def update(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if request.method == 'POST':
        form = PostForm(request.POST,
                        instance=post)  #update 할 때는 instance=post로 filtering
        if form.is_valid():
            form.save()
            return redirect(
                'blog:detail',
                pk=pk)  #redirect에는 view의 이름을 가져올 수 도 있지만 어떤 application인지 확인하자
    else:
        form = PostForm(instance=post)
    return render(request, 'blog/update.html', {'form': form})
예제 #7
0
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST, request.FILES)
        if form.is_valid():
            te = form.save()

            return redirect('../../', permanent=True)
    else:
        form = PostForm()
    return render(request, 'blog/post_edit.html', {'form': form})
예제 #8
0
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'blog/post_edit.html', {'form': form})
예제 #9
0
def post_add(request):
    author = request.user
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = author
            post.save()
            return redirect('/index/')
    else:
        form = PostForm()
    return render(request, "post_add.html", {"form" : form})
예제 #10
0
파일: views.py 프로젝트: snripa/WildWorld
def post_add(request):
    author = request.user
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = author
            post.save()
            return redirect('/index/')
    else:
        form = PostForm()
    return render(request, "post_add.html", {"form": form})
예제 #11
0
def post_edit(request, pk):
    post = get_object_or_404(Post, pk=pk)
    form_class = PostForm
    form = form_class(request.POST or None)
    if request.method == "POST":
        form = PostForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = PostForm(instance=post)
    return render(request, 'blog/post_edit.html', {'form':form})
예제 #12
0
def post_form(request):
    print(request.method)
    if request.user.is_authenticated:
        if request.method == "POST":
            print("request in post method {}".format(request.method))
            form = PostForm(request.POST)
            print(form)
            print(type(form))
            if form.is_valid():
                try:
                    p = form.save()

                    messages.success(request, " form submited successfully")
                except:
                    messages.error(request, "somthing went wrong")
        return render(request, BLOG_TEMPLATE + "/blog_post.html", {'form': PostForm, 'name': request.user})