fix topic removing

This commit is contained in:
slav0nic 2009-10-21 13:35:14 +03:00
parent adbc29fdec
commit d0a41876fd
2 changed files with 19 additions and 15 deletions

View file

@ -216,14 +216,30 @@ class Post(models.Model):
def delete(self, *args, **kwargs):
self_id = self.id
head_post_id = self.topic.posts.latest().id
head_post_id = self.topic.posts.order_by('created')[0].id
forum = self.topic.forum
topic = self.topic
self.last_topic_post.clear()
self.last_forum_post.clear()
super(Post, self).delete(*args, **kwargs)
#if post was last in topic - remove topic
if self_id == head_post_id:
self.topic.delete()
topic.delete()
else:
try:
topic.last_post = Post.objects.filter(topic=topic).latest()
except Post.DoesNotExist:
topic.last_post = None
topic.post_count = Post.objects.filter(topic=topic).count()
topic.save()
try:
forum.last_post = Post.objects.filter(topic__forum=forum).latest()
except Post.DoesNotExist:
forum.last_post = None
forum.post_count = Post.objects.filter(topic__forum=forum).count()
forum.topic_count = Topic.objects.filter(forum=forum).count()
forum.save()
class Reputation(models.Model):

View file

@ -22,16 +22,6 @@ def post_saved(instance, **kwargs):
notify_topic_subscribers(post)
def post_deleted(instance, **kwargs):
post = instance
post.topic.post_count = Post.objects.filter(topic=post.topic).count()
post.topic.last_post = Post.objects.filter(topic=post.topic).latest()
post.topic.save()
post.topic.forum.post_count = Post.objects.filter(topic__forum=post.topic.forum).count()
post.topic.forum.last_post = Post.objects.filter(topic__forum=post.topic.forum).latest()
post.topic.forum.save()
def pm_saved(instance, **kwargs):
notify_pm_recipients(instance)
@ -47,5 +37,3 @@ def topic_saved(instance, **kwargs):
post_save.connect(post_saved, sender=Post)
post_save.connect(pm_saved, sender=PrivateMessage)
post_save.connect(topic_saved, sender=Topic)
post_delete.connect(post_deleted, sender=Post)