Add and display htmx comments to arbitrary Django models.
Project description
Comments
Overview
Enable basic commenting functionality for an arbitrary Django model that contains an AbstractCommentable
mixin class.
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
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. This app produces those actions through urls. See the following shell commands that show the desired url routes per sentinel instance:
>>> obj = Sentinel.objects.create(title="A sample title") # instance is made, e.g. id=1, id=2, etc.
>>> obj.add_comment_url # url to add a comment to `A sample title`
Quickstart
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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea169c9c6c6e7745abf133db406fb4f8ff9d8f56a21f24e7ee168f61dd592d2b |
|
MD5 | 1108ea8d7a7833a2d34c8a25310eedec |
|
BLAKE2b-256 | c8522d6fa3f408d99956c9b288de1a0ebb6fe19509033b5240809d8b172e4c15 |
Hashes for django_add_comments-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f4973440f1231d8fd3ff98ca91a7e8d7093b623909825bc877f2994d2bd9687 |
|
MD5 | 185a55e689d369b4f3bbb9765d20db4a |
|
BLAKE2b-256 | c9101398346ba5b5bcb1f66ac0ec5a9f7b26e4107b536119e106c15b94d65ae2 |