Changeset 153:29e8f38274e2
- Timestamp:
- Oct 21, 2009 2:35:14 PM (4 years ago)
- Branch:
- default
- Location:
- apps/forum
- Files:
-
- 2 edited
-
models.py (modified) (1 diff)
-
signals.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/forum/models.py
r152 r153 217 217 def delete(self, *args, **kwargs): 218 218 self_id = self.id 219 head_post_id = self.topic.posts.latest().id 219 head_post_id = self.topic.posts.order_by('created')[0].id 220 forum = self.topic.forum 221 topic = self.topic 220 222 self.last_topic_post.clear() 221 223 self.last_forum_post.clear() 222 224 super(Post, self).delete(*args, **kwargs) 223 224 225 #if post was last in topic - remove topic 225 226 if self_id == head_post_id: 226 self.topic.delete() 227 topic.delete() 228 else: 229 try: 230 topic.last_post = Post.objects.filter(topic=topic).latest() 231 except Post.DoesNotExist: 232 topic.last_post = None 233 topic.post_count = Post.objects.filter(topic=topic).count() 234 topic.save() 235 try: 236 forum.last_post = Post.objects.filter(topic__forum=forum).latest() 237 except Post.DoesNotExist: 238 forum.last_post = None 239 forum.post_count = Post.objects.filter(topic__forum=forum).count() 240 forum.topic_count = Topic.objects.filter(forum=forum).count() 241 forum.save() 242 227 243 228 244 -
apps/forum/signals.py
r149 r153 23 23 24 24 25 def post_deleted(instance, **kwargs):26 post = instance27 post.topic.post_count = Post.objects.filter(topic=post.topic).count()28 post.topic.last_post = Post.objects.filter(topic=post.topic).latest()29 post.topic.save()30 post.topic.forum.post_count = Post.objects.filter(topic__forum=post.topic.forum).count()31 post.topic.forum.last_post = Post.objects.filter(topic__forum=post.topic.forum).latest()32 post.topic.forum.save()33 34 35 25 def pm_saved(instance, **kwargs): 36 26 notify_pm_recipients(instance) … … 48 38 post_save.connect(pm_saved, sender=PrivateMessage) 49 39 post_save.connect(topic_saved, sender=Topic) 50 51 post_delete.connect(post_deleted, sender=Post)
Note: See TracChangeset
for help on using the changeset viewer.
