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
15
attachment: django-forum-deletebug.r16.patch
(3.2 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Index: models.py
===================================================================
--- models.py (revision 16)
+++ models.py (working copy)
@@ -26,8 +26,21 @@
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')
+ #forum_latest_post = models.ForeignKey('Post', blank=True, null=True, related_name='forum_latest_post')
+ def _get_forum_latest_post(self):
+ """This gets the latest post for the forum"""
+ if not hasattr(self, '__forum_latest_post'):
+ try:
+ self.__forum_latest_post = Post.objects\
+ .filter(thread__forum__pk=self.id).latest("time")
+ except Post.DoesNotExist:
+ self.__forum_latest_post = None
+
+ return self.__forum_latest_post
+
+ forum_latest_post = property(_get_forum_latest_post)
+
def _recurse_for_parents_slug(self, forum_obj):
#This is used for the urls
p_list = []
@@ -142,10 +155,25 @@
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')
+ latest_post_time = models.DateTimeField(blank=True, null=True)
+ #thread_latest_post = models.ForeignKey('Post', blank=True, null=True, related_name='thread_latest_post')
+
+ def _get_thread_latest_post(self):
+ """This gets the latest post for the thread"""
+ if not hasattr(self, '__thread_latest_post'):
+ try:
+ self.__thread_latest_post = Post.objects\
+ .filter(thread__pk=self.id).latest("time")
+ except Post.DoesNotExist:
+ self.__thread_latest_post = None
+
+ return self.__thread_latest_post
+
+ thread_latest_post = property(_get_thread_latest_post)
+
class Meta:
- ordering = ('-sticky', '-thread_latest_post')
+ ordering = ('-sticky', '-latest_post_time')
def save(self):
if not self.id:
@@ -183,15 +211,33 @@
if new_post:
t = Thread.objects.get(id=self.thread.id)
- t.thread_latest_post_id = self.id
+ t.latest_post_time = self.time
t.posts += 1
t.save()
f = Forum.objects.get(id=self.thread.forum.id)
- f.forum_latest_post_id = self.id
+ #f.forum_latest_post_id = self.id
f.posts += 1
f.save()
+ def delete(self):
+ try:
+ latest_post = Post.objects.exclude(pk=self.id).latest('time')
+ latest_post_time = latest_post.time
+ except Post.DoesNotExist:
+ latest_post_time = None
+
+ t = Thread.objects.get(id=self.thread.id)
+ t.posts -= 1
+ t.latest_post_time = latest_post_time
+ t.save()
+
+ f = Forum.objects.get(id=self.thread.forum.id)
+ f.posts -= 1
+ f.save()
+
+ super(Post, self).delete()
+
class Meta:
ordering = ('-time',)
Powered by
Google Project Hosting