from django.contrib import admin from .models import ProductCategory, Product, ProductImage class ProductImageInline(admin.TabularInline): model = ProductImage extra = 3 fields = ('image', 'caption_zh', 'caption_en', 'sort_order') @admin.register(ProductCategory) class ProductCategoryAdmin(admin.ModelAdmin): list_display = ('name_zh', 'name_en', 'slug', 'sort_order', 'is_active') list_filter = ('is_active',) list_editable = ('sort_order', 'is_active') search_fields = ('name_zh', 'name_en', 'slug') prepopulated_fields = {'slug': ('name_en',)} fieldsets = ( ('基本信息', { 'fields': ('name_zh', 'name_en', 'slug', 'image') }), ('描述', { 'fields': ('description_zh', 'description_en'), 'classes': ('collapse',) }), ('排序', { 'fields': ('sort_order', 'is_active') }), ) @admin.register(Product) class ProductAdmin(admin.ModelAdmin): list_display = ('name_zh', 'category', 'model', 'sort_order', 'is_active', 'is_featured') list_filter = ('category', 'is_active', 'is_featured') list_editable = ('sort_order', 'is_active', 'is_featured') search_fields = ('name_zh', 'name_en', 'model', 'slug') prepopulated_fields = {'slug': ('name_en',)} inlines = [ProductImageInline] fieldsets = ( ('基本信息', { 'fields': ('category', 'name_zh', 'name_en', 'slug', 'model', 'main_image') }), ('摘要与描述', { 'fields': ('summary_zh', 'summary_en', 'description_zh', 'description_en') }), ('视频', { 'fields': ('video_url', 'video_file'), 'classes': ('collapse',) }), ('特点与参数', { 'fields': ('features_zh', 'features_en', 'specs_zh', 'specs_en'), 'classes': ('collapse',) }), ('下载', { 'fields': ('download_file',), 'classes': ('collapse',) }), ('SEO', { 'fields': ('seo_title_zh', 'seo_title_en', 'seo_keywords_zh', 'seo_keywords_en', 'seo_description_zh', 'seo_description_en'), 'classes': ('collapse',) }), ('状态', { 'fields': ('sort_order', 'is_active', 'is_featured') }), )