Source

flat_forum / flat_forum / models.py

Full commit
from django.db import models
from datetime import datetime

from taggit.models import TaggedItem
from taggit.managers import TaggableManager

import re

from flat_forum.fields import ProfileField

class Profile(models.Model):
    user = ProfileField('auth.User', related_name='forum_profile')

    def __unicode__(self):
        return self.user.get_full_name() or self.user.username

class PostManager(models.Manager):
    def tags_for_post(self, post=None, content=None):
        if content is None:
            content = post.content
        return [
            tag
            for tag in TaggedItem.tags_for(Post)
            if re.search(r'\b%s\b' % tag.name, content, re.I|re.M)
        ]

class Post(models.Model):
    reply_to = models.ForeignKey('self', blank=True, null=True, related_name='replies')
    posted_by = models.ForeignKey('Profile', related_name='posts')
    created = models.DateTimeField(default=datetime.now)
    subject = models.CharField(max_length=200)
    content = models.TextField(blank=True)

    tags = TaggableManager(blank=True)

    objects = PostManager()

    class Meta:
        get_latest_by = 'created'
        ordering = ('created',)
        permissions = (
            ('can_reply', 'Can reply to Posts'),
        )
    def __unicode__(self):
        return 'Post on %s by %s' % (self.created, self.posted_by,)

    @models.permalink
    def get_absolute_url(self):
        return 'post-detail', (), {'pk': self.pk}

    # XXX Should cache this result
    def get_root(self):
        if self.reply_to_id:
            return self.reply_to.get_root()
        return self

    @property
    def post_date(self):
        return self.created.date()