Commits

cur...@tinbrain.net  committed 8822e5a

Tidied up models to actually work
Thread slugs need only be unique together with their forum
Removed URL pattern name namespaces
Added Thread.latest_post

  • Participants
  • Parent commits 53ca29f

Comments (0)

Files changed (1)

File gnocchi_forum/models.py

     order = models.IntegerField(default=0, help_text='Highest number first')
 
     class Meta:
-        ordering = ('-order')
+        ordering = ('-order',)
+        verbose_name_plural = 'Gategories'
 
+    def __unicode__(self):
+        return self.name
     @models.permalink
     def get_absolute_url(self):
-        return 'gnocchi_forum:category-details', (), {'category': self.slug}
+        return 'category-detail', (), {'category': self.slug}
 
 class Forum(models.Model):
     '''Topic within a Category'''
-    title = models.CharField(max_lengtu=256)
+    title = models.CharField(max_length=256)
     slug = models.SlugField(unique=True)
     category = models.ForeignKey(Category)
     description = models.TextField(blank=True)
             ('category', 'slug',),
         )
 
+    def __unicode__(self):
+        return u'[%s] %s' % (self.category, self.title,)
     @models.permalink
     def get_absolute_url(self):
-        return 'gnocchi_forum:forum-details', (), {
-            'forum': self.slug
-        }
+        return (
+            'forum-detail',
+            (),
+            {'forum': self.slug},
+        )
 
 class Thread(models.Model):
     '''List of posts within a Topic'''
-    title = models.CharField(max_lengtu=256)
-    slug = models.SlugField(unique=True)
+    title = models.CharField(max_length=256)
+    slug = models.SlugField()
     forum = models.ForeignKey(Forum)
     pinned = models.BooleanField(default=False)
     state = models.CharField(max_length=16, choices=THREAD_STATE_CHOICES)
 
     @models.permalink
     def get_absolute_url(self):
-        return 'gnocchi_forum:forum-details', (), {
+        return 'thread-detail', (), {
             'forum': self.forum.slug,
             'thread': self.slug,
-        }
+        },
 
+    def last_post(self):
+        try:
+            return self.post_set.order_by('-created')[0]
+        except IndexError:
+            return None
 
 class Post(models.Model):
     thread = models.ForeignKey(Thread)
 
     @models.permalink
     def get_absolute_url(self):
-        return 'gnocchi_forum:post-details', (), {
+        return 'post-detail', (), {
             'forum_id': self.thread.forum.pk,
             'thread_id': self.thread.pk,
             'object_id': self.pk,