Spaces:
Running
Running
File size: 3,186 Bytes
0bb49b0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | from django.contrib import admin
from .models import Size, Color, Product, ProductVariant, Inventory, BodyScan, Recommendation
@admin.register(Size)
class SizeAdmin(admin.ModelAdmin):
list_display = ['name', 'chest_min', 'chest_max', 'waist_min', 'waist_max', 'height_min', 'height_max']
search_fields = ['name']
@admin.register(Color)
class ColorAdmin(admin.ModelAdmin):
list_display = ['name', 'hex_code', 'category']
list_filter = ['category']
search_fields = ['name']
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ['name', 'category', 'gender', 'price', 'created_at']
list_filter = ['category', 'gender']
search_fields = ['name', 'description']
ordering = ['name']
class InventoryInline(admin.TabularInline):
model = Inventory
extra = 0
fields = ['quantity', 'low_stock_threshold', 'last_updated']
readonly_fields = ['last_updated']
@admin.register(ProductVariant)
class ProductVariantAdmin(admin.ModelAdmin):
list_display = ['product', 'size', 'color', 'sku', 'get_stock_quantity', 'get_stock_status']
list_filter = ['product__category', 'size', 'color']
search_fields = ['product__name', 'sku']
inlines = [InventoryInline]
def get_stock_quantity(self, obj):
try:
return obj.inventory.quantity
except Inventory.DoesNotExist:
return 'N/A'
get_stock_quantity.short_description = 'Stock'
def get_stock_status(self, obj):
try:
inv = obj.inventory
if inv.is_out_of_stock:
return 'π΄ Out of Stock'
elif inv.is_low_stock:
return 'π‘ Low Stock'
else:
return 'π’ In Stock'
except Inventory.DoesNotExist:
return 'N/A'
get_stock_status.short_description = 'Status'
@admin.register(Inventory)
class InventoryAdmin(admin.ModelAdmin):
list_display = ['product_variant', 'quantity', 'low_stock_threshold', 'get_status', 'last_updated']
list_filter = ['last_updated']
search_fields = ['product_variant__product__name', 'product_variant__sku']
def get_status(self, obj):
if obj.is_out_of_stock:
return 'π΄ Out of Stock'
elif obj.is_low_stock:
return 'π‘ Low Stock'
else:
return 'π’ In Stock'
get_status.short_description = 'Status'
@admin.register(BodyScan)
class BodyScanAdmin(admin.ModelAdmin):
list_display = ['session_id', 'height', 'chest', 'waist', 'shoulder_width', 'skin_tone', 'undertone', 'scanned_at']
list_filter = ['skin_tone', 'undertone', 'scanned_at']
search_fields = ['session_id']
readonly_fields = ['session_id', 'scanned_at']
ordering = ['-scanned_at']
@admin.register(Recommendation)
class RecommendationAdmin(admin.ModelAdmin):
list_display = ['body_scan', 'product', 'recommended_size', 'recommended_fit', 'priority', 'created_at']
list_filter = ['recommended_size', 'recommended_fit', 'created_at']
search_fields = ['body_scan__session_id', 'product__name']
readonly_fields = ['created_at']
ordering = ['-created_at', '-priority']
|