Add Django backend, 1C integration, deploy config and API docs
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.
This commit is contained in:
1 parent
5f8d37357d
commit
756f40353b
130 files changed
+10066
No files matched your search
@@ -0,0 +1,118 @@
|
||||
from django.contrib import admin
|
||||
from django.db.models import Count
|
||||
|
||||
from .models import Category, Product, ProductImage
|
||||
|
||||
|
||||
class ProductImageInline(admin.TabularInline):
|
||||
model = ProductImage
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Category)
|
||||
class CategoryAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"name",
|
||||
"slug",
|
||||
"parent",
|
||||
"is_active",
|
||||
"sort_order",
|
||||
"products_count",
|
||||
)
|
||||
list_filter = ("is_active",)
|
||||
search_fields = ("name", "external_id")
|
||||
prepopulated_fields = {"slug": ("name",)}
|
||||
autocomplete_fields = ("parent",)
|
||||
actions = ("activate", "deactivate")
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).annotate(products_count=Count("products"))
|
||||
|
||||
@admin.display(description="Товаров", ordering="products_count")
|
||||
def products_count(self, obj):
|
||||
return obj.products_count
|
||||
|
||||
@admin.action(description="Активировать выбранные")
|
||||
def activate(self, request, queryset):
|
||||
updated = queryset.update(is_active=True)
|
||||
self.message_user(request, f"Активировано: {updated}")
|
||||
|
||||
@admin.action(description="Деактивировать выбранные")
|
||||
def deactivate(self, request, queryset):
|
||||
updated = queryset.update(is_active=False)
|
||||
self.message_user(request, f"Деактивировано: {updated}")
|
||||
|
||||
|
||||
@admin.register(Product)
|
||||
class ProductAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"sku",
|
||||
"name",
|
||||
"category",
|
||||
"price",
|
||||
"stock",
|
||||
"stock_status",
|
||||
"is_hit",
|
||||
"is_new",
|
||||
"is_active",
|
||||
)
|
||||
list_filter = ("is_active", "is_hit", "is_new", "stock_status", "category")
|
||||
search_fields = ("name", "sku", "external_id", "brand")
|
||||
readonly_fields = ("external_id", "external_updated_at", "created_at", "updated_at")
|
||||
autocomplete_fields = ("category",)
|
||||
date_hierarchy = "created_at"
|
||||
inlines = [ProductImageInline]
|
||||
actions = (
|
||||
"mark_hit",
|
||||
"unmark_hit",
|
||||
"mark_new",
|
||||
"unmark_new",
|
||||
"activate",
|
||||
"deactivate",
|
||||
)
|
||||
fieldsets = (
|
||||
(
|
||||
"Идентификация",
|
||||
{"fields": ("external_id", "sku", "name", "slug", "brand", "category")},
|
||||
),
|
||||
("Цены и остатки", {"fields": ("price", "old_price", "stock", "stock_status")}),
|
||||
("Описание", {"fields": ("short_description", "description", "attributes")}),
|
||||
("Флаги", {"fields": ("is_hit", "is_new", "is_active")}),
|
||||
("Служебное", {"fields": ("external_updated_at", "created_at", "updated_at")}),
|
||||
)
|
||||
|
||||
@admin.action(description="Отметить как «Хит продаж»")
|
||||
def mark_hit(self, request, queryset):
|
||||
updated = queryset.update(is_hit=True)
|
||||
self.message_user(request, f"Отмечено: {updated}")
|
||||
|
||||
@admin.action(description="Снять «Хит продаж»")
|
||||
def unmark_hit(self, request, queryset):
|
||||
updated = queryset.update(is_hit=False)
|
||||
self.message_user(request, f"Снято: {updated}")
|
||||
|
||||
@admin.action(description="Отметить как «Новинка»")
|
||||
def mark_new(self, request, queryset):
|
||||
updated = queryset.update(is_new=True)
|
||||
self.message_user(request, f"Отмечено: {updated}")
|
||||
|
||||
@admin.action(description="Снять «Новинка»")
|
||||
def unmark_new(self, request, queryset):
|
||||
updated = queryset.update(is_new=False)
|
||||
self.message_user(request, f"Снято: {updated}")
|
||||
|
||||
@admin.action(description="Активировать выбранные")
|
||||
def activate(self, request, queryset):
|
||||
updated = queryset.update(is_active=True)
|
||||
self.message_user(request, f"Активировано: {updated}")
|
||||
|
||||
@admin.action(description="Деактивировать выбранные")
|
||||
def deactivate(self, request, queryset):
|
||||
updated = queryset.update(is_active=False)
|
||||
self.message_user(request, f"Деактивировано: {updated}")
|
||||
|
||||
|
||||
@admin.register(ProductImage)
|
||||
class ProductImageAdmin(admin.ModelAdmin):
|
||||
list_display = ("product", "url", "is_main", "sort_order")
|
||||
search_fields = ("product__name", "product__sku")
|
||||
Reference in new issue
Block a user