Skip to main content

Add and display htmx comments to arbitrary Django models.

Project description

Comments

Enable basic commenting functionality for an arbitrary Django model that contains an AbstractCommentable mixin class.

Overview

from comments.models import AbstractCommentable

# sentinels/models.py
class Sentinel(AbstractCommentable): # arbitrary
    title = models.CharField(max_length=50)
    ...

# comments/models.py
class AbstractCommentable(models.Model): # generic foreign relationships to comments
    comments = GenericRelation(Comment, related_query_name="%(app_label)s_%(class)ss")

    class Meta:
        abstract = True

Once setup, can dive into understanding the frontend through the use of htmx and hyperscript.

Quickstart

  1. Install app
  2. Add generic comments to your model

Premises

Any model e.g. Essay, Article, etc... and (not just Sentinel) can be "commentable". But for purposes of demonstration, we'll use "sentinel" to refer to the arbitrary model that will have its own comments field.

More specifically, the instances of such sentinel – e.g. Sentinel with id=1, Sentinel with id=2, etc. – need to have their own related comments. This means having the ability to:

  1. View a list of existing comments on sentinel id=1
  2. Adding a comment (if logged in) on sentinel id=2
  3. Deleting a comment (if made by an author)
  4. Updating an added comment's content (if made by an author)
  5. Toggling visibility of the comment to the public.

All instances of the Sentinel model therefore will need their own commenting actions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-add-comments-0.0.3.tar.gz (46.5 kB view hashes)

Uploaded Source

Built Distribution

django_add_comments-0.0.3-py3-none-any.whl (50.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page