Django Comment System, It can be associated with any given model.
Project description
Installation & Configuration
Install using pip
python -m pip install django-comment-system
or Clone the repository and copy comment folder and paste in project folder.
git clone https://github.com/mahyar-amiri/django-comment-system.git
Add comment.apps.CommentConfig to installed_apps in the settings.py file after django.contrib.auth.
# setting.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # MY APPS 'comment.apps.CommentConfig', ] # your account login url LOGIN_URL = 'admin:login' # or reverse_lazy('admin:login') MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media'
Add path('comment/', include('comment.urls')), to urlpatterns in the urls.py file.
# urls.py from django.urls import path, include urlpatterns = [ path('comment/', include('comment.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Connect comments to target model. In models.py add the field comments as a GenericRelation field to the required model.
NOTE: Please note that the field name must be comments NOT comment.
# models.py from django.db import models from django.contrib.contenttypes.fields import GenericRelation from comment.models import Comment class Article(models.Model): title = models.CharField(max_length=20) content = models.TextField() # the field name should be comments comments = GenericRelation(Comment)
Do migrations
python manage.py migrate
Usage
In the template (e.g. post_detail.html) add the following template tags where obj is the instance of post model.
{% load comment_tags %}
Add the following template tags where you want to render comments.
{% render_comments request obj settings_slug='default-config' %} {# Render all the comments belong to the passed object "obj" #}
if your context_object_name is not obj (e.g article) replace obj with context_object_name.
{% render_comments request obj=article settings_slug='default-config' %}
Project details
Release history Release notifications | RSS feed
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-comment-system-2.10.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 112588b66647fda4e0d229b064936ada3000e139e2a9c627ffca9fc2b86a39bc |
|
MD5 | 10400fa34123a0ec983a53678607d00f |
|
BLAKE2b-256 | eab342f1a61feecfe752c9967004994f115d6cb96cf3babaa542e42cae7ca7f0 |
Hashes for django_comment_system-2.10.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3541965ec0b617f34d151ff95d37ffc3956d13fd4cd30643c0e52d7aebc68799 |
|
MD5 | 320b23512af2e03e2a1ec164d8f75ec3 |
|
BLAKE2b-256 | 9e3aab05b217bbe2f8e700bf7dbcafac68436d077c197bdbaa2d53f9d472f59f |