本文整理汇总了Python中comments.models.Comment.parent_comment方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.parent_comment方法的具体用法?Python Comment.parent_comment怎么用?Python Comment.parent_comment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comments.models.Comment
的用法示例。
在下文中一共展示了Comment.parent_comment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import parent_comment [as 别名]
def handle(self, *args, **options):
posts = list(Post.objects.all())
users = list(get_user_model().objects.all())
for i in range(1000):
c = Comment()
c.text = u"Комментарий {}".format(i)
parent_post = random.choice(posts)
c.parent_post = parent_post
parent_comments = list(parent_post.comments.all())
if parent_comments:
c.parent_comment = random.choice(parent_comments)
c.author = random.choice(users)
c.save()
示例2: post_comment
# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import parent_comment [as 别名]
def post_comment(user, content, obj, parent=None):
'''
'''
comment = Comment(id=get_available_id(),
user=user,
content=content,
content_object=obj)
if parent and isinstance(parent, Comment):
comment.parent_comment = parent
parent.n_comment += 1
parent.save()
topics = obj.topics.all()
if isinstance(obj, Link):
comment.way = 'l'
for topic in topics:
topic_ship_update(topic=topic, user=user,
domain=obj.domain, is_comment=True)
elif isinstance(obj, Discuss):
comment.way = 'd'
for topic in topics:
topic_ship_update(topic=topic, user=user,
is_comment=True)
else:
return False
comment.save()
if parent and isinstance(parent, Comment):
if user != parent.user:
creat_remind(parent.user, user, REMIND_NEW_COMMENT, comment)
else:
if user != obj.user:
creat_remind(obj.user, user, REMIND_NEW_COMMENT, comment)
if isinstance(obj, Link):
Dynamic.objects.create(column=user.userprofile.get_column(),
way=WAY_LINK_COMMENT,
content_object=comment,
comment_object=obj)
elif isinstance(obj, Discuss):
Dynamic.objects.create(column=user.userprofile.get_column(),
way=WAY_DISCUSS_COMMENT,
content_object=comment,
comment_object=obj)
DiscussIndex.objects.filter(discuss=obj).update(
last_active_time=timezone.now(),
last_active_user=user)
obj.last_active_time = timezone.now()
obj.last_active_user = user
if not user.userdata.discusses.filter(id=obj.id).count():
user.userdata.discusses.add(obj)
else:
pass
obj.n_comment += 1
obj.save()
UserData.objects.filter(user=user).update(n_comments=F('n_comments') + 1)
return comment