.. _comments: ******** Comments ******** Django Cast provides a full commenting system built on top of `django-contrib-comments `_. Comments can be enabled or disabled at three levels: App level The global :ref:`CAST_COMMENTS_ENABLED ` setting (defaults to ``False``). Blog level Each ``Blog`` model has a ``comments_enabled`` field (defaults to ``True``). Post level Each ``Post`` model also has a ``comments_enabled`` field (defaults to ``True``). A comment form is only rendered when **all three levels** evaluate to enabled. .. _comments_configuration: Configuration ============= To enable the built-in comments integration, set: .. code-block:: python COMMENTS_APP = "cast.comments" .. _comments_settings: Settings -------- ``CAST_COMMENTS_ENABLED`` Master switch for the entire comment system. Set to ``True`` to enable comments. Defaults to ``False``. ``CAST_COMMENTS_EXCLUDE_FIELDS`` Tuple of form field names to hide from the comment form. Useful for removing fields like ``email``, ``url``, or ``title``. Defaults to ``()``. Also accepts the legacy name ``FLUENT_COMMENTS_EXCLUDE_FIELDS``. ``CAST_COMMENTS_DEFAULT_MODERATOR`` Dotted Python path to a moderator class. The class must provide ``allow()`` and ``moderate()`` methods (see :ref:`comments_moderation`). Set to ``"none"``, ``"null"``, ``"default"``, or ``""`` to use a built-in ``NullModerator`` that allows all comments and never moderates. Defaults to ``"cast.moderation.Moderator"`` (the built-in spam filter moderator). Also accepts the legacy name ``FLUENT_COMMENTS_DEFAULT_MODERATOR``. ``CAST_COMMENTS_FORM_CSS_CLASS`` CSS class applied to the comment form. Defaults to ``"comments-form form-horizontal"``. ``CAST_COMMENTS_LABEL_CSS_CLASS`` CSS class for form labels (crispy-forms). Defaults to ``"col-sm-2"``. ``CAST_COMMENTS_FIELD_CSS_CLASS`` CSS class for form field wrappers (crispy-forms). Defaults to ``"col-sm-10"``. ``CRISPY_TEMPLATE_PACK`` The crispy-forms template pack used for rendering form fields and AJAX error messages. Not specific to django-cast but affects how comment form errors are rendered in AJAX responses. Defaults to ``"bootstrap4"``. Example configuration: .. code-block:: python COMMENTS_APP = "cast.comments" CAST_COMMENTS_ENABLED = True CAST_COMMENTS_EXCLUDE_FIELDS = ("email", "url", "title") CAST_COMMENTS_DEFAULT_MODERATOR = "cast.moderation.Moderator" .. _comments_internals: How ``COMMENTS_APP`` Integration Works ======================================= Setting ``COMMENTS_APP = "cast.comments"`` tells ``django-contrib-comments`` to use the cast comments package. The package provides two hook functions in its ``__init__.py``: ``get_model()`` Returns ``CastComment``, a **proxy model** (``managed = False``) that adds a custom manager with ``select_related("user")`` for efficient queryset loading. When ``threadedcomments`` is installed, ``CastComment`` inherits from ``ThreadedComment`` instead of the plain ``Comment`` model. ``get_form()`` Returns ``CastCommentForm``, which extends the appropriate base form (``ThreadedCommentForm`` or ``CommentForm``). It removes fields listed in ``CAST_COMMENTS_EXCLUDE_FIELDS`` and reorders the remaining fields so security fields (``content_type``, ``object_pk``, ``timestamp``, ``security_hash``) appear first, the ``parent`` field follows in threaded mode, visible fields come next, and the ``honeypot`` field is placed last. .. _comments_threaded_replies: Threaded Replies ================ If ``threadedcomments`` is in ``INSTALLED_APPS``, threaded replies are enabled automatically. The comment system detects the package at startup and switches the base model from ``django_comments.models.Comment`` to ``threadedcomments.models.ThreadedComment``, which adds a ``parent`` foreign key for nesting. When threaded mode is active: - The comment form includes a hidden ``parent`` field. - Each rendered comment shows a "reply" link that sets the ``parent`` value via the JavaScript layer (see :ref:`comments_ajax_posting`). - The comment list template uses ``fill_tree`` and ``annotate_tree`` filters from ``threadedcomments`` to produce nested ``