Vendor testimonial serializers Documentation
This section outlines the serializers used in the Vendor Testimonials API. These serializers handle the transformation of data between complex types (e.g., Django models) and Python data types (e.g., JSON), facilitating the representation of data for API requests and responses.
Serializers
- User Detail Serializer:
UserDetailSerializer - Vendor Testimonial Serializer:
VendorTestimonialSerializer
1. User Detail Serializer
Serializer Overview
UserDetailSerializer is used to serialize the user's details related to a vendor. It includes fields like the user's first name, last name, address, and photo.
Fields
| Field | Type | Description |
|---|---|---|
first_name |
string |
The first name of the user. |
last_name |
string |
The last name of the user. |
address |
string |
The address of the user. |
photo |
string |
The photo of the user (URL). |
Example Response
{
"first_name": "John",
"last_name": "Doe",
"address": "123 Vendor St.",
"photo": "https://example.com/path/to/photo.jpg"
}
2. Vendor Testimonial Serializer
Serializer Overview
VendorTestimonialSerializer is used to serialize the testimonial data related to a vendor. It includes information such as the testimonial's ID, vendor details, rating, content, and creation date.
Fields
- id (
integer): The unique identifier for the testimonial. - vendor (
object): Contains the vendor details (company name, telephone, and user information). - shop (
object): Contains the vendor shop. - rating (
integer): The rating provided in the testimonial. - content (
string): The content of the testimonial. - created_at (
datetime): The date and time when the testimonial was created.
Vendor Data Structure (Nested in vendor)
- company_name (
string): The name of the vendor's company. - telephone (
string): The contact number of the vendor. - first_name (
string): The first name of the vendor's associated user. - last_name (
string): The last name of the vendor's associated user. - address (
string): The address of the vendor's associated user. - photo (
string): The photo URL of the vendor's associated user.
Example Response
{
"id": 1,
"vendor": {
"company_name": "Vendor Name",
"telephone": "123-456-7890",
"first_name": "John",
"last_name": "Doe",
"address": "123 Vendor St.",
"photo": "https://example.com/path/to/photo.jpg"
},
"rating": 5,
"content": "Excellent service!",
"created_at": "2024-12-01T12:00:00Z"
}
Serializer Methods
VendorTestimonialSerializer.get_vendor(self, obj)
This method is responsible for getting the vendor's details associated with the testimonial. It retrieves the user's details via the UserDetailSerializer and returns the vendor data along with the user's information.