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
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:
- View a list of existing comments on sentinel id=1
- Adding a comment (if logged in) on sentinel id=2
- Deleting a comment (if made by an
author
) - Updating an added comment's
content
(if made by anauthor
) - 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
Built Distribution
Hashes for django-add-comments-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e489360ac770f17caec7ed39bef442f9de98d473662f28e1aab920b70366c3 |
|
MD5 | 4b563fe016b73360b161613615ea9f09 |
|
BLAKE2b-256 | 5df2b88ce69c314f6b50434405933ce7fb85672f5c53bde044f7f8aaf4859b2b |
Hashes for django_add_comments-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c772eb8e44d895d45e97f1ba41ca4a8bac633fc57feeb135ce24aca613c7e4ac |
|
MD5 | dceb57edffb07eabcdc530f5e796a65a |
|
BLAKE2b-256 | 11ad055d3c09ae4d2c09fdad24a55258b1678aa9876a97821579214c936185ac |