发表新评论和回复现有评论之间的主要区别是什么?

what is key difference between posting a new comment and replying to existing comments?

我想找出在 comment form 中发布新评论和回复现有评论之间的主要区别,以及它们如何在 django_comments_xtd?

源码看了半天也没找到答案

在django_comments_xtd中,系统通过参考reply_to数据字段来区分评论是对先前post的回复/还是新的独立评论。

对于新评论,reply_to 字段的默认值为“0”,但对于回复之前的评论(比如 ID=14),则 reply_to 数据字段将具有值“14”。

对于源代码,您可以参考的地方之一是 python 文件 forms.py(下面附有摘录)。当然还有其他地方使用此 reply_to 数据字段来呈现网站,因此您可以搜索 reply_to 字符串以发现您是否对此有更多兴趣方面

class XtdCommentForm(CommentForm):
    followup = forms.BooleanField(required=False,
                                  label=_("Notify me about follow-up comments"))
    reply_to = forms.IntegerField(required=True, initial=0,
                                  widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        comment = kwargs.pop("comment", None)
        if comment:
            initial = kwargs.pop("initial", {})
            initial.update({"reply_to": comment.pk})
            kwargs["initial"] = initial
            followup_suffix = ('_%d' % comment.pk)
        else:
            followup_suffix = ''

        super(CommentForm, self).__init__(*args, **kwargs)

        self.fields['name'].label = _("Name")
        self.fields['name'].widget = forms.TextInput(
            attrs={'placeholder': _('name'), 'class': 'form-control'})

        self.fields['email'].label = _("Mail")
        self.fields['email'].help_text = _("Required for comment verification")
        self.fields['email'].widget = forms.TextInput(
            attrs={'placeholder': _('mail address'), 'class': 'form-control'})

        self.fields['url'].label = _("Link")
        self.fields['url'].required = False
        self.fields['url'].widget = forms.TextInput(attrs={
                'placeholder': _('url your name links to (optional)'),
                'class': 'form-control'})

        self.fields['comment'].widget = forms.Textarea(
            attrs={'placeholder': _('Your comment'), 'class': 'form-control'})
        self.fields['comment'].max_length = settings.COMMENT_MAX_LENGTH
        self.fields['comment'].widget.attrs.pop('cols')
        self.fields['comment'].widget.attrs.pop('rows')

        self.fields['followup'].widget.attrs['id'] = (
            'id_followup%s' % followup_suffix)
        self.fields['followup'].widget.attrs['class'] = "custom-control-input"
        self.fields['followup'].initial = settings.COMMENTS_XTD_DEFAULT_FOLLOWUP

    def get_comment_model(self):
        return TmpXtdComment

    def get_comment_create_data(self, site_id=None):
        data = super(CommentForm, self).get_comment_create_data(site_id=site_id)
        ctype = data.get('content_type')
        object_pk = data.get('object_pk')
        model = apps.get_model(ctype.app_label, ctype.model)
        target = model._default_manager.get(pk=object_pk)
        data.update({'thread_id': 0, 'level': 0, 'order': 1,
                     'parent_id': self.cleaned_data['reply_to'],
                     'followup': self.cleaned_data['followup'],
                     'content_object': target})
        return data