Example #1
0
def post(request):
    """
    posting questions
    """
    if request.method == "POST":
        postform = PostForm(request.POST)
        if postform.is_valid():
            post = postform.save(commit=False)
            post.user = request.user
            post.save()

            # Tags
            for _tagname in request.POST.get("tags").split(","):
                _tagname = _tagname.strip()

                if _tagname:
                    _tag, _created = Tag.objects.get_or_create(name=_tagname, defaults={"name": _tagname})
                    post.tags.add(_tag)

            return HttpResponseRedirect(reverse("home"))

    elif request.method == "GET":
        postform = PostForm()

    return render(request, "post.html", {"postform": postform})
Example #2
0
def post(request):
    """
    posting questions
    """
    if request.method == "POST":
        postform = PostForm(request.POST)
        if postform.is_valid():
            _post = postform.save(commit=False)
            _post.user = request.user
            _post.save()

            # tags(ManyToManyField)
            for _tagname in request.POST.get('tags', '').split(','):
                _tagname = _tagname.strip()

                # When only _tagname is not blank
                if _tagname:
                    _tag, _created = Tag.objects.get_or_create(
                        name=_tagname, defaults={'name': _tagname})
                    _post.tags.add(_tag)

            return HttpResponseRedirect(reverse('home'))
    elif request.method == "GET":
        postform = PostForm()

    return render(request, "post.html", {
        'postform': postform,
    })
Example #3
0
def post(request):
    """
    posting questions
    """
    if request.method == "POST":
        postform = PostForm(request.POST)
        if postform.is_valid():
            post = postform.save(commit=False)
            post.user = request.user
            post.save()

            return HttpResponseRedirect(reverse('home'))

    elif request.method == "GET":
        postform = PostForm()

    return render(request, "post.html", {
        'postform': postform,
    })
Example #4
0
def post(request):
    """
    posting questions
    """
    if request.method == "POST":
        postform = PostForm(request.POST)
        if postform.is_valid():
            post = postform.save(commit=False)
            post.user = request.user
            post.save()

            return HttpResponseRedirect(reverse('home'))

    elif request.method == "GET":
        postform = PostForm()

    return render(request, "post.html", {
        'postform': postform,
    })