本文整理汇总了Python中forums.models.Post.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Post.delete方法的具体用法?Python Post.delete怎么用?Python Post.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forums.models.Post
的用法示例。
在下文中一共展示了Post.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_last_and_only_post_in_thread
# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import delete [as 别名]
def test_delete_last_and_only_post_in_thread(self):
"""Deleting the only post in a thread should delete the thread"""
forum = Forum.objects.get(pk=1)
thread = Thread(title="test", forum=forum, creator_id=118533)
thread.save()
post = Post(thread=thread, content="test", author=thread.creator)
post.save()
eq_(1, thread.post_set.count())
post.delete()
eq_(0, Thread.uncached.filter(pk=thread.id).count())
示例2: test_last_post_updated
# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import delete [as 别名]
def test_last_post_updated(self):
"""Adding/Deleting the last post in a thread and forum should
update the last_post field
"""
thread = Thread.objects.get(pk=4)
user = User.objects.get(pk=118533)
# add a new post, then check that last_post is updated
new_post = Post(thread=thread, content="test", author=user)
new_post.save()
forum = Forum.objects.get(pk=1)
thread = Thread.objects.get(pk=thread.id)
eq_(forum.last_post.id, new_post.id)
eq_(thread.last_post.id, new_post.id)
# delete the new post, then check that last_post is updated
new_post.delete()
forum = Forum.objects.get(pk=1)
thread = Thread.objects.get(pk=thread.id)
eq_(forum.last_post.id, 25)
eq_(thread.last_post.id, 25)