本文整理汇总了Python中django.contrib.comments.models.Comment.is_reply_comment方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.is_reply_comment方法的具体用法?Python Comment.is_reply_comment怎么用?Python Comment.is_reply_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.comments.models.Comment
的用法示例。
在下文中一共展示了Comment.is_reply_comment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comment_reply_post_create_handler
# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import is_reply_comment [as 别名]
def comment_reply_post_create_handler(sender, instance, action, model, pk_set,
using, **kwargs):
if action == 'post_add':
for replied_to_comment in instance.replied_to_comments.all():
moderator_settings = getattr(settings, 'MODERATOR', None)
offset_timedelta = timedelta(seconds=1)
if moderator_settings:
if 'REPLY_BEFORE_COMMENT' in moderator_settings:
if moderator_settings['REPLY_BEFORE_COMMENT']:
offset_timedelta = timedelta(seconds=-1)
created = False
# We use try except DoesNotExist instead of get or create to
# allow us to add a is_reply_comment to a newly created comment
# which facilitates realtime_comment_classifier below to distinguish
# between normal comments and reply comments.
try:
comment_obj = Comment.objects.get(
content_type=replied_to_comment.content_type,
object_pk=replied_to_comment.object_pk,
site=replied_to_comment.site,
submit_date=replied_to_comment.submit_date + offset_timedelta,
user=instance.user,
)
except Comment.DoesNotExist:
comment_obj = Comment(
content_type=replied_to_comment.content_type,
object_pk=replied_to_comment.object_pk,
site=replied_to_comment.site,
submit_date=replied_to_comment.submit_date + offset_timedelta,
user=instance.user,
comment=instance.comment_text,
)
comment_obj.is_reply_comment = True
comment_obj.save()
created = True
if not created:
comment_obj.comment = instance.comment_text
comment_obj.save()
if comment_obj not in instance.reply_comments.all():
instance.reply_comments.add(comment_obj)