本文整理匯總了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