Django reaction System, It can be associated with any given model.
Project description
Installation
Install using pip
python -m pip install django-reaction-system
or Clone the repository then copy reaction folder and paste in project folder.
git clone https://github.com/mahyar-amiri/django-reaction-system.git
Configuration
Add reaction.apps.ReactionConfig to installed_apps after django.contrib.auth in the settings.py file. Add MEDIA_URL and MEDIA_ROOT.
# setting.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # MY APPS 'reaction.apps.ReactionConfig', ] ... MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media'
Add path('reaction/', include('reaction.urls')), and media root to urlpatterns in the project urls.py file.
# urls.py from django.urls import path, include from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('reaction/', include('reaction.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Connect reaction to target model. In models.py add the field reactions as a GenericRelation field to the required model.
NOTE: Please note that the field name must be reactions NOT reaction.
# models.py from django.db import models from django.contrib.contenttypes.fields import GenericRelation from reaction.models import Reaction class Article(models.Model): title = models.CharField(max_length=20) content = models.TextField() # the field name should be reactions reactions = GenericRelation(Reaction)
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 reaction_tags %}
Add the following template tag to load stylesheet.
{% render_reaction_import %}
Add the following template tags where you want to render reactions.
{% render_reaction request obj settings_slug='default-config' %} {# Render all the reactions belong to the passed object "obj" #}
if your context_object_name is not obj (e.g. article) replace obj with context_object_name.
{% render_reaction request obj=article settings_slug='default-config' %}
Add render_reaction_script tag at the end of the last render_reaction tag.
{% render_reaction_import %} {% render_reaction request=request obj=article settings_slug='default-config' %} {% render_reaction request=request obj=article settings_slug='second-config' %} {% render_reaction_script %}
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-reaction-system-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc95827052177ef7fa51f7774a220a561291518e1a8bd2c36f175dfdb4ac58b0 |
|
MD5 | 3f9bdcfdab8cd833ebc35697db4a8ea7 |
|
BLAKE2b-256 | f7465302d9ebcc480777f994ec3764eff6a3b6e10423af6fd8d2a68ae9dcbe2f |
Hashes for django_reaction_system-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e236719086b7d97a594bc57c92602fc0884338ac861577f87d5dc2057bb99188 |
|
MD5 | de0d4c695986e9406053222286bb68f9 |
|
BLAKE2b-256 | ad25cd0e4dd81284716c438b56c3d3630a69bb31c235f0c1371897a5c4fa655a |