Commits

Anonymous committed 02e601a

Add tagging to models
Remove bodgy old profile accessor
Add post root methdo

  • Participants
  • Parent commits 833d8c7

Comments (0)

Files changed (1)

File flat_forum/models.py

 from django.db import models
 from datetime import datetime
 
+from taggit.managers import TaggableManager
+
 from flat_forum.fields import ProfileField
 
 class Profile(models.Model):
     def __unicode__(self):
         return self.user.get_full_name() or self.user.username
 
-from django.contrib.auth.models import User
-User.forum_profile = property(lambda u: Profile.objects.get_or_create(user=u)[0])
-
 class Post(models.Model):
     reply_to = models.ForeignKey('self', blank=True, null=True, related_name='replies')
     posted_by = models.ForeignKey('Profile', related_name='posts')
     subject = models.CharField(max_length=200)
     content = models.TextField(blank=True)
 
+    tags = TaggableManager()
+
     class Meta:
         get_latest_by = 'created'
-        ordering = ('created',)
+        ordering = ('-created',)
         permissions = (
             ('can_reply', 'Can reply to Posts'),
         )
     @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()