Skip to main content

Django rating System, It can be associated with any given model.

Project description

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 %}

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

django-rating-system-1.0.6.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_rating_system-1.0.6-py3-none-any.whl (48.3 kB view details)

Uploaded Python 3

File details

Details for the file django-rating-system-1.0.6.tar.gz.

File metadata

  • Download URL: django-rating-system-1.0.6.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for django-rating-system-1.0.6.tar.gz
Algorithm Hash digest
SHA256 0077928cf85d3602670f0706fce7c2767edc1c397c2e3cb2480be26204c07d9d
MD5 f8adc9faf4a596fff68103ae98d1933f
BLAKE2b-256 fefeb1d257adbc3ba83f27e4950c953ba58ca52c01ecdcea78fe4277106b5498

See more details on using hashes here.

File details

Details for the file django_rating_system-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_rating_system-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 53c5d769939e0a61de836b4895e3b5571b166e7634bc03ff572de3df85552ce8
MD5 f4ca65f8d4590ccd636236d2ae669ce7
BLAKE2b-256 390be20e21306c3d1295eeadd499ffae769ad7a1727c80bd1029a37eff5dd810

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page