Skip to content

Add reviews and ratings functionality to your django application

Notifications You must be signed in to change notification settings

jackkweyunga/djreviews

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DJANGO REVIEWS & RATING

Add reviews and ratings functionalities to your dango app.

Installation

pip install djreviews

Usage

Extending functionality in models

from django.db import models
from djreviews.models import BaseReviewModel, BaseReviewedModel


class ProductReview(BaseReviewModel):
    """
    Product Reviews
    """


class Product(BaseReviewedModel):
    name = models.CharField(max_length=20)
    description = models.TextField()
    objects = models.Manager()

    # important
    REVIEW_MODEL = ProductReview

usage in views

product = Product.objects.get(pk=product_pk)
customer = Customer.objects.get(pk=customer_pk)

product.add_review(
    content=review_text,
    rating=rating_score,
    reviewer=customer,
)

# OR

ProductReview.objects.add_review(
    content=review_text,
    rating=rating_score,
    reviewed_object=product,
    reviewer_object=customer,
)

in templates

{% for review in object.reviews.all|dictsortreversed:"id" %}
<div>
    <p>{{ review.reviewer }}</p>
    <p>rating: {{ review.rating }}</p>
    <p>review: {{ review.content }}</p>
</div>
{% empty %}
<p>No reviews</p>
{% endfor %}

About

Add reviews and ratings functionality to your django application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published