L
L
larionov_n2014-08-05 23:00:10
Django
larionov_n, 2014-08-05 23:00:10

How to include django-threadedcomments?

Good afternoon, help me connect a package with tree-like comments to Django. https://github.com/HonzaKral/django-threadedcomments
Can't figure out how they work with Django. Do I need my own model for comments? There are already models in the source code of the package, and I can add them through the admin panel, they appear in the database. But I do not understand how to save the form with comments? Do I need a post handler for a form in views?
Here's what I did while reading the Readme:
1) Installed a package with comments via pycharm.
2) Added everything you need to settings.py in installed_apps
3) Added routing to urls.py:

urlpatterns = patterns('',
    url(r'^comments/', include('django.contrib.comments.urls')),
    url(
        r'^blog/view/(?P<slug>[^\.]+).html',
        'blog.views.view_post',
        name='view_blog_post')
)

4) In the template with the post, I loaded the tags from the comments:
{% load threadedcomments_tags %}
    {% render_comment_list for post %}
    {% render_comment_form for post %}
    {% get_comment_count for post as comment_count %}
    <p>This post has {{ comment_count }} comments.</p>

5) I copied from gitHub from examples folder with templates comments -> core (form.html, list.html), (base.html, posted.html).
6) In my view.py - Post (blog article) GET request handler is as follows:
As I understand it, post should be processed here?
def view_post(request, slug):
    item = get_object_or_404(Post, slug=slug)
    item.addViewed()
    c = {
        'post': item,
        'breadcrumbs': breadcrumbs('blog.views.view_post', obj=item)}
    c.update(csrf(request))
    return render_to_response('blog/' + 'view_post.html', c)

7) Form template
Here it is necessary to add a method to the action that processes the url in views.py?
<div class="form-comment" id="form-comment">
    <form action="comments/postfree" method="post">{% csrf_token %}
        {{ form.as_p }}{# just to keep the example simple. Consider using django-crispy-forms in real life #}
        <p>
            <input type="submit" value="Submit Comment"/>
            <a href="#c0" id="cancel_reply">cancel reply</a>
        </p>
    </form>
</div>

I can’t understand the Example on GitHub, it’s logical that the post of my form should be somehow processed and saved to the comment table created after syncdb in the database. I also don’t understand where Post is associated with comments, I thought that it’s enough just to call tags in any template and the comment app will understand which entity the comment was added to? :) I’ve been working with Python recently, so I still don’t quite understand its features and Django. Tell me what I missed, everything should be much simpler :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
larionov_n, 2014-08-05
@larionov_n

I launched an archive with an example from github, the comments started working, in general I will deal with the source :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question