Review Models
Review Model
The Review model stores feedback provided by users for products. It includes a rating, a review headline, text, images, a video, and a helpful count. Reviews are linked to both the product being reviewed and the user submitting the review.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
product |
ForeignKey | Yes | A foreign key to the Product model, representing the product being reviewed. |
user |
ForeignKey | Yes | A foreign key to the User model, representing the user who wrote the review. |
rating |
CharField | No | The rating given by the user for the product. The choices are 1 to 5 stars. |
headline |
CharField | No | A headline or summary of the review. |
review_text |
TextField | No | The body text of the review. |
review_image1 |
ImageField | No | An optional image associated with the review. Validated for file extensions and custom image validation. |
review_image2 |
ImageField | No | An optional second image associated with the review. Validated for file extensions and custom image validation. |
review_image3 |
ImageField | No | An optional third image associated with the review. Validated for file extensions and custom image validation. |
review_image4 |
ImageField | No | An optional fourth image associated with the review. Validated for file extensions and custom image validation. |
review_image5 |
ImageField | No | An optional fifth image associated with the review. Validated for file extensions and custom image validation. |
review_video |
FileField | No | An optional video file associated with the review. Validated for allowed video formats. |
helpful_count |
PositiveIntegerField | Yes | A counter to track how many users found the review helpful. |
created_at |
DateTimeField | Yes | Auto-generated timestamp when the review was created. |
updated_at |
DateTimeField | Yes | Auto-generated timestamp when the review was last updated. |
Custom Methods
__str__: This method returns a string representation of theReviewobject, displaying the user's username, product name, and rating (e.g.,john_doe - Product Name - 5 Stars).
Report Model
The Report model is used to store reports made by users about reviews. A user can report a review for various reasons, such as inappropriate content or being fake. Reports are linked to both the user making the report and the review being reported.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
user |
ForeignKey | Yes | A foreign key to the User model, representing the user who created the report. |
review |
ForeignKey | Yes | A foreign key to the Review model, representing the review being reported. |
reason |
CharField | Yes | The reason for reporting the review. The choices are off_topic, inappropriate, fake, or other. |
description |
TextField | No | A detailed description provided by the user about why the review is being reported. |
created_at |
DateTimeField | Yes | Auto-generated timestamp when the report was created. |
Custom Methods
__str__: This method returns a string representation of theReportobject, displaying the username of the user who created the report and the review being reported (e.g.,Report by john_doe on review 1).
HelpfulVote Model
The HelpfulVote model stores votes made by users on reviews to mark them as helpful or not. This model tracks whether the user found a particular review helpful and ensures that each user can only vote once on each review.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
user |
ForeignKey | Yes | A foreign key to the User model, representing the user who voted. |
review |
ForeignKey | Yes | A foreign key to the Review model, representing the review being voted on. |
is_helpful |
BooleanField | Yes | A boolean field indicating whether the user found the review helpful or not. |
Custom Methods
__str__: This method returns a string representation of theHelpfulVoteobject, displaying the username of the user who voted and the review ID (e.g.,john_doe voted helpful for review 1).
Custom Constraints
- Unique Together: The combination of
userandreviewis unique, ensuring that a user can only vote once per review.
Custom Methods Overview
Reviewincludes a__str__method that provides a string representation of the review, displaying the user, product, and rating.Reportincludes a__str__method that provides a string representation of the report, displaying the user and the review being reported.HelpfulVoteincludes a__str__method that provides a string representation of the vote, displaying the user and the review ID.