Report Serializer Documentation
This section outlines the serializer used in the Report API. The ReportSerializer is responsible for transforming the data between complex types (e.g., Django models) and Python data types (e.g., JSON), allowing the creation, update, and retrieval of reports related to reviews.
Serializers
- Report Serializer:
ReportSerializer
1. Report Serializer
Serializer Overview
ReportSerializer is used to serialize report data. A report is created when a user reports a review. The serializer includes details such as the review being reported, the user who made the report, the reason for the report, and any additional description provided by the user.
Fields
| Field | Type | Description |
|---|---|---|
id |
integer |
The unique identifier for the report. |
user |
integer |
The user who created the report. |
review |
integer |
The review being reported. |
review_text |
string |
The text of the review being reported. |
product_name |
string |
The name of the product being reviewed. |
reason |
string |
The reason for reporting the review (e.g., offensive, spam). |
description |
string |
A detailed description provided by the user about the reason for the report. |
created_at |
datetime |
The timestamp when the report was created. |
Example Response
{
"id": 1,
"user": 100,
"review": 200,
"review_text": "This product is awful!",
"product_name": "Product Name",
"reason": "Offensive content",
"description": "The review contains inappropriate language.",
"created_at": "2024-12-06T14:30:00Z"
}
Serializer Methods
ReportSerializer.validate(self, data)
This method ensures that a user cannot report the same review multiple times. If a report already exists for the given user and review, it raises a ValidationError to prevent duplicate reports.