Fix latest topic listings

This commit is contained in:
Trever Fischer
2012-04-17 13:14:09 -04:00
parent 820c904d39
commit d1c93cd675
3 changed files with 6 additions and 8 deletions

View File

@@ -42,11 +42,9 @@ class Forum(MPTTModel):
def topicCount(self):
return self.topic_set.count()
def latestTopic(self):
try:
return self.topic_set.extra(order_by = ['created'])[0]
except IndexError, e:
return None
def freshestTopic(self):
freshestForum = self.get_descendants(True).extra(order_by = ['-topic__updated'])[0]
return freshestForum.topic_set.extra(order_by = ['-updated'])[0]
@models.permalink
def get_absolute_url(self):

View File

@@ -9,7 +9,7 @@ def random_quote(request):
return {}
def forum_activity(request):
latestPosts = forums.models.Post.objects.all().order_by('updated')[0:5]
latestPosts = forums.models.Post.objects.all().order_by('-updated')[0:5]
return {'latestForumPosts': latestPosts}
def login_form(request):

View File

@@ -20,8 +20,8 @@
{% endif %}
</ul></td>
<td>{{ f.topicCount }}</td>
{% if f.latestTopic %}
<td class="author-info"><div class="avatar">{% avatar f.latestTopic.lastPost.user 32 %}</div><ul><li>{{f.latestTopic.lastPost.user}}</li><li>{{f.latestTopic.created}}</li><li>In <em><a href="{{f.latestTopic.get_absolute_url}}">{{f.latestTopic}}</a></em></ul></td>
{% if f.freshestTopic%}
<td class="author-info"><div class="avatar">{% avatar f.freshestTopic.lastPost.user 32 %}</div><ul><li>{{f.freshestTopic.lastPost.user}}</li><li>{{f.freshestTopic.created}}</li><li>In <em><a href="{{f.freshestTopic.get_absolute_url}}">{{f.freshestTopic}}</a></em></ul></td>
{% else %}
<td><em>No posts...</em></td>
{% endif %}