My favorites
▼
|
Sign in
django-forum
Simple Django Forum Component
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
16
attachment: fix_foreignkeys.diff
(2.0 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Index: models.py
===================================================================
--- models.py (revision 16)
+++ models.py (working copy)
@@ -26,8 +26,20 @@
description = models.TextField()
threads = models.IntegerField(default=0)
posts = models.IntegerField(default=0)
- forum_latest_post = models.ForeignKey('Post', blank=True, null=True, related_name='forum_latest_post')
+ @property
+ def forum_latest_post(self):
+ try:
+ cursor = connection.cursor()
+ cursor.execute('''select forum_post.id from forum_post
+ inner join forum_thread on forum_post.thread_id = forum_thread.id
+ inner join forum_forum on forum_thread.forum_id = forum_forum.id where forum_forum.id = %s or forum_forum.parent_id = %s
+ order by forum_post.time desc limit 1''' % (self.pk, self.pk))
+ last_post_id = cursor.fetchall()[0][0]
+ return Post.objects.get(pk=last_post_id)
+ except:
+ return None
+
def _recurse_for_parents_slug(self, forum_obj):
#This is used for the urls
p_list = []
@@ -142,10 +154,20 @@
closed = models.BooleanField(blank=True, null=True)
posts = models.IntegerField(default=0)
views = models.IntegerField(default=0)
- thread_latest_post = models.ForeignKey('Post', blank=True, null=True, related_name='thread_latest_post')
+ @property
+ def thread_latest_post(self):
+ try:
+ cursor = connection.cursor()
+ cursor.execute('''select forum_post.id from forum_post where thread_id = %s
+ order by forum_post.time desc limit 1''' % self.pk)
+ last_post_id = cursor.fetchall()[0][0]
+ return Post.objects.get(pk=last_post_id)
+ except:
+ return None
+
class Meta:
- ordering = ('-sticky', '-thread_latest_post')
+ ordering = ('-sticky', )
def save(self):
if not self.id:
Powered by
Google Project Hosting