https://github.com/jackkweyunga/djreviews
Add reviews and ratings functionality to your django application
https://github.com/jackkweyunga/djreviews
Last synced: over 1 year ago
JSON representation
Add reviews and ratings functionality to your django application
- Host: GitHub
- URL: https://github.com/jackkweyunga/djreviews
- Owner: jackkweyunga
- Created: 2023-03-09T14:41:44.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-09T15:09:59.000Z (over 3 years ago)
- Last Synced: 2025-03-24T14:08:29.823Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DJANGO REVIEWS & RATING
Add reviews and ratings functionalities to your dango app.
## Installation
```shell
pip install djreviews
```
## Usage
Extending functionality in models
```python
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
```python
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
```html
{% for review in object.reviews.all|dictsortreversed:"id" %}
{{ review.reviewer }}
rating: {{ review.rating }}
review: {{ review.content }}
{% empty %}
No reviews
{% endfor %}
```