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.
76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
from django.contrib import admin
|
|
from django.db.models import Count
|
|
|
|
from .models import Address, OtpCode, User
|
|
|
|
|
|
class AddressInline(admin.TabularInline):
|
|
model = Address
|
|
extra = 0
|
|
|
|
|
|
@admin.register(User)
|
|
class UserAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"phone",
|
|
"email",
|
|
"full_name",
|
|
"bonus_balance",
|
|
"orders_count",
|
|
"is_active",
|
|
"is_staff",
|
|
"date_joined",
|
|
)
|
|
list_filter = ("is_active", "is_staff", "is_superuser")
|
|
search_fields = ("phone", "email", "first_name", "last_name")
|
|
ordering = ("-date_joined",)
|
|
readonly_fields = ("date_joined", "last_login")
|
|
inlines = [AddressInline]
|
|
|
|
def get_queryset(self, request):
|
|
return (
|
|
super()
|
|
.get_queryset(request)
|
|
.annotate(orders_count=Count("orders"))
|
|
.select_related("bonus_account")
|
|
)
|
|
|
|
@admin.display(description="Бонусы", ordering="bonus_account__balance")
|
|
def bonus_balance(self, obj):
|
|
account = getattr(obj, "bonus_account", None)
|
|
return account.balance if account else 0
|
|
|
|
@admin.display(description="Заказов", ordering="orders_count")
|
|
def orders_count(self, obj):
|
|
return obj.orders_count
|
|
|
|
|
|
@admin.register(OtpCode)
|
|
class OtpCodeAdmin(admin.ModelAdmin):
|
|
list_display = ("phone", "purpose", "expires_at", "attempts", "is_used", "created_at")
|
|
list_filter = ("purpose", "is_used")
|
|
search_fields = ("phone",)
|
|
readonly_fields = (
|
|
"phone",
|
|
"code_hash",
|
|
"purpose",
|
|
"expires_at",
|
|
"attempts",
|
|
"is_used",
|
|
"created_at",
|
|
"updated_at",
|
|
)
|
|
|
|
def has_add_permission(self, request):
|
|
return False
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
return False
|
|
|
|
|
|
@admin.register(Address)
|
|
class AddressAdmin(admin.ModelAdmin):
|
|
list_display = ("user", "title", "city", "street", "house", "is_default")
|
|
search_fields = ("user__phone", "city", "street")
|
|
list_filter = ("is_default",)
|