I forgot to change out the name of the node to be path, which is what
it is. That's why I can sort on it.

Thank you, I'll give it a try.

On Mar 2, 12:04 am, Mihail Lukin <[email protected]> wrote:
> I'm not sure what "node" is, but maybe you're looking for something
> like this:
>
> def comment_walk(comment, comment_list, level=0):
>     comment_list.append((comment, level))
>     for child in comment.children.all().order_by('node'):
>         comment_walk(child, comment_list, level+1)
>
> def post_view(request, post_id):
>     post = get_object_or_404(Post, pk=post_id)
>     level1 = post.comment_set.filter(parent=None).order_by('node')
>     comment_list = []
>     for comment in level1:
>         comment_walk(comment, comment_list)
>     return render_to_response('view_post.html', {'post': post,
> 'comment_list': comment_list})
>
> in "view_post.html" you'll be able to choose indentation by second
> item of the tuple, which is in the comment_list variable. I'm sorry if
> there are errors, I didn't validate that code, this is just an idea.
>
> On 2 ÍÁÒ, 09:53, Merrick <[email protected]> wrote:
>
> > I have a comments model that is setup to do threaded replies. I am
> > having trouble figuring out how to display the comments in a threaded
> > manner, i.e. tree.
>
> > My model looks like this:
>
> > class Comment(models.Model):
> > š š post = šmodels.ForeignKey(Post, null=True, blank=True)
> > š š user = models.ForeignKey(User, null=True, blank=True)
> > š š comment = models.TextField(null=True, blank=True)
> > š š parent = models.ForeignKey('self', null=True, blank=True,
> > default=None,
> > š š š š related_name='children')
> > š š node = models.CharField(null=True, blank=True, default=None,
> > max_length=1024)
> > š š created = models.DateTimeField(auto_now_add=True, editable=False)
>
> > When I sort by node, I get the correct order of comments.
>
> > I was hoping someone has an idea of how to iterate through the
> > comments for a particular post, and have them appear as a tree.
>
> > Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to