milton / threadedcomments /

from django.db import models
from django.contrib.comments.models import Comment
from mptt.models import MPTTModel, TreeForeignKey

### COMMENTS ###

class MPTTComment(MPTTModel, Comment):
    """ Threaded comments - Add support for the parent comment store and MPTT traversal"""
    # a link to comment that is being replied, if one exists
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
    title = models.CharField(null=True, blank=True, max_length=255)

    class MPTTMeta:
        # comments on one level will be ordered by date of creation

    class Meta:

    def depth(self):
        return self.get_ancestors().count()