Skip to main content

Installation

  1. Install using pip

    python -m pip install django-rating-system

    or Clone the repository then copy rating folder and paste in project folder.

    git clone https://github.com/mahyar-amiri/django-rating-system.git

Configuration

  1. Add rating.apps.RatingConfig 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
        'rating.apps.RatingConfig',
    ]
    
    ...
    
    MEDIA_URL = '/media/'
    MEDIA_ROOT = BASE_DIR / 'media'
  2. Add path('rating/', include('rating.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('rating/', include('rating.urls')),
    ]
    
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  3. Connect ratings to target model. In models.py add the field ratings as a GenericRelation field to the required model.

    NOTE: Please note that the field name must be ratings NOT rating.

    # models.py
    
    from django.db import models
    from django.contrib.contenttypes.fields import GenericRelation
    from rating.models import Rating
    
    class Article(models.Model):
        title = models.CharField(max_length=20)
        content = models.TextField()
        # the field name should be ratings
        ratings = GenericRelation(Rating)
  4. Do migrations

    python manage.py migrate

Usage

  1. In the template (e.g. post_detail.html) add the following template tags where obj is the instance of post model.

    {% load rating_tags %}
  2. Add the following template tag to load stylesheet.

    {% render_rating_import %}
  3. Add the following template tags where you want to render ratings.

    {% render_rating request obj settings_slug='default-config' %}  {# Render all the ratings belong to the passed object "obj" #}

    if your context_object_name is not obj (e.g. article) replace obj with context_object_name.

    {% render_rating request obj=article settings_slug='default-config' %}
  4. Add the following template tag to show rating information.

    {% render_rating_info request=request obj=article settings_slug='default-config' %}

    use custom_template if you want to render your own template.

    {% render_rating_info request=request obj=article settings_slug='default-config' custom_template='my_custom_rating_info.html' %}
  5. Add render_rating_script tag at the end of the last render_rating tag.

    {% render_rating_import %}
    
    {% render_rating request=request obj=article settings_slug='default-config' %}
    {% render_rating_info request=request obj=article settings_slug='default-config' %}
    
    {% render_rating request=request obj=article settings_slug='like-config' %}
    {% render_rating_info request=request obj=article settings_slug='like-config' custom_template='rating/rating_info.html' %}
    
    {% render_rating_script %}

Metadata

Release files for django-rating-system 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-rating-system 1.1.1
File Size Uploaded Provenance Actions
django-rating-system-1.1.1.tar.gz 13.8 kB Without provenance Details for django-rating-system-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-rating-system 1.1.1
File Interpreter ABI Platform Actions
django_rating_system-1.1.1-py3-none-any.whl Python 3 none any Details for django_rating_system-1.1.1-py3-none-any.whl

Total release size: 31.7 kB

Release files / django-rating-system-1.1.1.tar.gz

Download URL django-rating-system-1.1.1.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cce9e1b86c9de6d47a68017b7f0fd0d1c579a1597422a1a44debdb62920d5922
BLAKE2b-256 checksum
How to use checksums
817ded8a93408d109b4dafc7e19377be1e0c817c42014a8252b8977ad21b8180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / django_rating_system-1.1.1-py3-none-any.whl

Download URL django_rating_system-1.1.1-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15dba151428a98e21dd8484db2250c91c8cbc17ce51e5d7bc23f887a7e5df4d5
BLAKE2b-256 checksum
How to use checksums
1592d92f5e61528fc4a4d21cb4ff37caa7804eb5ec640fa701adc8bb780e403d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Security for django-rating-system 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page