fix #87: topic deleting droped forum in cascade

This commit is contained in:
slav0nic 2011-05-16 10:40:54 +03:00
parent 33bc6df2c0
commit 2ebd1af94f

View file

@ -129,12 +129,26 @@ class Topic(models.Model):
class Meta:
ordering = ['-updated']
get_latest_by = 'updated'
verbose_name = _('Topic')
verbose_name_plural = _('Topics')
def __unicode__(self):
return self.name
def delete(self, *args, **kwargs):
last_post = self.posts.latest()
last_post.last_forum_post.clear()
forum = self.forum
super(Topic, self).delete(*args, **kwargs)
try:
forum.last_post = Topic.objects.filter(forum__id=forum.id).latest().last_post
except Topic.DoesNotExist:
forum.last_post = None
forum.topic_count = Topic.objects.filter(forum__id=forum.id).count()
forum.post_count = Post.objects.filter(topic__forum__id=forum.id).count()
forum.save()
@property
def head(self):
try: