Signature Collection Serializer
This section outlines the serializers used in the Collection 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
- Collection Serializer:
CollectionSerializer
1. Collection Serializer
Serializer Overview
CollectionSerializer is used to serialize collection data. It includes the collection's ID, name, slug, image URL, description, call-to-action URL, activity status, and the count of products associated with the collection.
Fields
| Field | Type | Description |
|---|---|---|
id |
integer |
The unique identifier for the collection. |
name |
string |
The name of the collection. |
slug |
string |
A URL-friendly version of the collection's name. |
image |
string |
The URL of the collection's image. This is an absolute URL generated using the get_image method. |
description |
string |
A brief description of the collection. |
cta_url |
string |
The call-to-action URL, typically directing users to more details about the collection. |
is_active |
boolean |
A boolean indicating whether the collection is active. |
product_count |
integer |
The number of products related to this collection. This value is dynamically calculated using the get_product_count method. |
Example Response
{
"id": 1,
"name": "Winter Collection",
"slug": "winter-collection",
"image": "https://example.com/media/images/winter-collection.jpg",
"description": "A collection of stylish winter wear to keep you warm and fashionable.",
"cta_url": "https://example.com/collections/winter",
"is_active": true,
"product_count": 25
}