示例#1
0
def post_create(request):
    form = PostForm(request.POST or None)
    if form.is_valid():
        obj = form.save(commit=False)
        obj.save()
        return redirect('list')
    context = {'form': form}
    return render(request, 'post_form.html', context)
示例#2
0
def post_update(request, slug=None):
    instance = get_object_or_404(Post, slug=slug)
    form = PostForm(request.POST or None, instance=instance)
    if form.is_valid():
        instance = form.save()
        instance.save()
        return HttpResponseRedirect(instance.get_absolute_url())
    context = {'post': instance, 'form': form}
    return render(request, 'post_form.html', context)
示例#3
0
def crearPost(request):
	if  request.POST.get("id_blog", "") != '':
		request.session["id_blog"] = request.POST.get("id_blog", "")
		form = PostForm()
	else:
		if request.method == 'POST':
			form = PostForm(request.POST)
			if form.is_valid():
				
				adminblog = Adminblog.objects.get(blog=request.session["id_blog"], user=request.user, permiso__in=[1,2])
				post = Post.objects.create(
					adminblog=adminblog,
					titulo=form.cleaned_data['titulo'],
					descripcion=form.cleaned_data['descripcion'],
					contenido=form.cleaned_data['contenido'],
					fecha_crea=timezone.now()
					)
				post.save()
		else:
			form = PostForm()
	return render_to_response("posts/post_crear.html", {'form': form}, context_instance=RequestContext(request))
示例#4
0
def p_create(request):
    # POST 방식으로 호출될 때
    if request.method == 'POST':
        post_form = PostForm(request.POST)  #post방식으로 전송된 데이터 전부 postform객체로

        if post_form.is_valid():  # 입력된 데이터가 유효하면,
            post_form.save()
            return redirect('posts:list')

    # GET 방식으로 호출될 때
    else:
        post_form = PostForm()
        return render(request, 'create.html', {'post_form': post_form})
示例#5
0
    def post(self, request):
        post = Post()
        post.owner = request.user
        form = PostForm(request.POST, request.FILES, instance=post)
        if form.is_valid():
            new_ad = form.save()
            form = PostForm()
            messages.success(request, 'Anuncio creado correctamente')

        context = {'form': form}
        return render(request, 'posts/form.html', context)
示例#6
0
def create_post(request):
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('feed')
    else:
        form = PostForm()
    return render(request=request,
                  template_name='posts/new.html',
                  context={
                      'form': form,
                      'user': request.user,
                      'profile': request.user.profile
                  })
示例#7
0
def p_update(request, post_id):
    post = get_object_or_404(Post, pk=post_id)

    # POST 방식으로 호출될 때
    if request.method == 'POST':
        post_form = PostForm(request.POST,
                             instance=post)  # post방식으로 전송된 데이터 전부 postform객체로

        if post_form.is_valid():  # 입력된 데이터가 유효하면,
            post_form.save()
            return redirect('posts:list')

    # GET 방식으로 호출될 때
    else:
        post_form = PostForm(instance=post)
        return render(request, 'create.html', {'post_form': post_form})
示例#8
0
 def get(self, request):
     form = PostForm()
     context = {'form': form}
     return render(request, 'posts/form.html', context)