Backend (Django 4.2 + DRF): - accounts: phone OTP login, JWT, profile, addresses - catalog: categories, products, images, filters, search, hits/new/related - orders: creation with Idempotency-Key, stock reservation, status history, cancel - loyalty: bonus accounts, promo codes, gift certificates - payments: payment records and YooKassa webhook handling - content: static pages, banners, site settings - integration: 1C exchange (catalog sync, order push via outbox, statuses, bonuses) - common: error envelope, pagination, request-id, integration auth, admin dashboard Infrastructure: Dockerfile, docker-compose (Postgres, Redis, Celery worker/beat, Nginx), requirements split by environment, OpenAPI contracts for site and 1C, architecture doc. Tests: 22 pytest cases covering catalog, orders, idempotency, OTP, integration.
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from rest_framework import serializers
|
|
|
|
from .models import Category, Product, ProductImage
|
|
|
|
|
|
class CategorySerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Category
|
|
fields = ["id", "name", "slug", "parent", "image_url", "sort_order"]
|
|
|
|
|
|
class ProductImageSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = ProductImage
|
|
fields = ["id", "url", "alt", "sort_order", "is_main"]
|
|
|
|
|
|
class ProductListSerializer(serializers.ModelSerializer):
|
|
main_image = serializers.CharField(read_only=True)
|
|
category = CategorySerializer(read_only=True)
|
|
|
|
class Meta:
|
|
model = Product
|
|
fields = [
|
|
"id",
|
|
"slug",
|
|
"name",
|
|
"sku",
|
|
"brand",
|
|
"price",
|
|
"old_price",
|
|
"stock_status",
|
|
"is_hit",
|
|
"is_new",
|
|
"main_image",
|
|
"category",
|
|
]
|
|
|
|
|
|
class ProductDetailSerializer(ProductListSerializer):
|
|
images = ProductImageSerializer(many=True, read_only=True)
|
|
|
|
class Meta(ProductListSerializer.Meta):
|
|
fields = ProductListSerializer.Meta.fields + [
|
|
"short_description",
|
|
"description",
|
|
"stock",
|
|
"attributes",
|
|
"images",
|
|
]
|