Introduces Cart and CartItem models, admin, serializers, and API endpoints for shopping cart management for both authenticated and anonymous users. Adds Review model, serializers, and endpoints for product reviews, including public creation and retrieval. Updates ProductImage ordering, enhances order save logic with notification, and improves product and order endpoints with new actions and filters. Includes related migrations for commerce, configuration, social chat, and Deutsche Post integration.
106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
from django.contrib import admin
|
|
from .models import (
|
|
Category, Product, ProductImage, Order, OrderItem,
|
|
Carrier, Payment, DiscountCode, Refund, Invoice, Cart, CartItem
|
|
)
|
|
|
|
|
|
@admin.register(Category)
|
|
class CategoryAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "url", "parent")
|
|
search_fields = ("name", "description")
|
|
prepopulated_fields = {"url": ("name",)}
|
|
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "price", "stock", "is_active", "category", "created_at")
|
|
search_fields = ("name", "description", "code")
|
|
list_filter = ("is_active", "category", "created_at")
|
|
prepopulated_fields = {"url": ("name",)}
|
|
|
|
|
|
@admin.register(ProductImage)
|
|
class ProductImageAdmin(admin.ModelAdmin):
|
|
list_display = ("product", "is_main", "alt_text")
|
|
list_filter = ("is_main",)
|
|
search_fields = ("product__name", "alt_text")
|
|
|
|
|
|
class OrderItemInline(admin.TabularInline):
|
|
model = OrderItem
|
|
extra = 0
|
|
readonly_fields = ("product", "quantity")
|
|
|
|
|
|
@admin.register(Order)
|
|
class OrderAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "user", "email", "status", "total_price", "currency", "created_at")
|
|
list_filter = ("status", "created_at", "country")
|
|
search_fields = ("email", "first_name", "last_name", "phone")
|
|
readonly_fields = ("created_at", "updated_at", "total_price")
|
|
inlines = [OrderItemInline]
|
|
|
|
|
|
@admin.register(OrderItem)
|
|
class OrderItemAdmin(admin.ModelAdmin):
|
|
list_display = ("order", "product", "quantity")
|
|
search_fields = ("order__id", "product__name")
|
|
|
|
|
|
@admin.register(Carrier)
|
|
class CarrierAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "shipping_method", "state", "shipping_price", "weight")
|
|
list_filter = ("shipping_method", "state", "returning")
|
|
search_fields = ("id",)
|
|
|
|
|
|
@admin.register(Payment)
|
|
class PaymentAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "payment_method", "created_at")
|
|
list_filter = ("payment_method", "created_at")
|
|
|
|
|
|
@admin.register(DiscountCode)
|
|
class DiscountCodeAdmin(admin.ModelAdmin):
|
|
list_display = ("code", "percent", "amount", "active", "valid_from", "valid_to", "used_count", "usage_limit")
|
|
list_filter = ("active", "valid_from", "valid_to")
|
|
search_fields = ("code", "description")
|
|
|
|
|
|
@admin.register(Refund)
|
|
class RefundAdmin(admin.ModelAdmin):
|
|
list_display = ("order", "reason_choice", "verified", "created_at")
|
|
list_filter = ("verified", "reason_choice", "created_at")
|
|
search_fields = ("order__id", "order__email", "reason_text")
|
|
|
|
|
|
@admin.register(Invoice)
|
|
class InvoiceAdmin(admin.ModelAdmin):
|
|
list_display = ("invoice_number", "issued_at", "due_date")
|
|
search_fields = ("invoice_number",)
|
|
readonly_fields = ("issued_at",)
|
|
|
|
|
|
class CartItemInline(admin.TabularInline):
|
|
model = CartItem
|
|
extra = 0
|
|
readonly_fields = ("product", "quantity", "added_at")
|
|
|
|
|
|
@admin.register(Cart)
|
|
class CartAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "user", "session_key", "created_at", "updated_at")
|
|
list_filter = ("created_at", "updated_at")
|
|
search_fields = ("user__email", "session_key")
|
|
readonly_fields = ("created_at", "updated_at")
|
|
inlines = [CartItemInline]
|
|
|
|
|
|
@admin.register(CartItem)
|
|
class CartItemAdmin(admin.ModelAdmin):
|
|
list_display = ("cart", "product", "quantity", "added_at")
|
|
list_filter = ("added_at",)
|
|
search_fields = ("cart__id", "product__name")
|
|
readonly_fields = ("added_at",)
|