Добавлена регистрация ConfigurableProduct в админке Django
Добавлены imports для ConfigurableProduct, ConfigurableProductOption, ConfigurableProductAttribute. Создан ConfigurableProductAdmin с инлайнами для вариантов и атрибутов. Поля variant_sku отображается в readonly режиме. Добавлен счетчик вариантов в list_display с цветовой индикацией. Организованы fieldsets для удобного редактирования.
This commit is contained in:
@@ -6,6 +6,7 @@ import nested_admin
|
|||||||
from .models import ProductCategory, ProductTag, Product, ProductKit, KitItem
|
from .models import ProductCategory, ProductTag, Product, ProductKit, KitItem
|
||||||
from .models import ProductPhoto, ProductKitPhoto, ProductCategoryPhoto
|
from .models import ProductPhoto, ProductKitPhoto, ProductCategoryPhoto
|
||||||
from .models import ProductVariantGroup, KitItemPriority, SKUCounter, CostPriceHistory
|
from .models import ProductVariantGroup, KitItemPriority, SKUCounter, CostPriceHistory
|
||||||
|
from .models import ConfigurableProduct, ConfigurableProductOption, ConfigurableProductAttribute
|
||||||
from .admin_displays import (
|
from .admin_displays import (
|
||||||
format_quality_badge,
|
format_quality_badge,
|
||||||
format_quality_display,
|
format_quality_display,
|
||||||
@@ -940,3 +941,57 @@ admin.site.register(ProductCategory, ProductCategoryAdminWithPhotos)
|
|||||||
admin.site.register(ProductTag, ProductTagAdmin)
|
admin.site.register(ProductTag, ProductTagAdmin)
|
||||||
admin.site.register(Product, ProductAdminWithPhotos)
|
admin.site.register(Product, ProductAdminWithPhotos)
|
||||||
admin.site.register(ProductKit, ProductKitAdminWithItemsAndPhotos)
|
admin.site.register(ProductKit, ProductKitAdminWithItemsAndPhotos)
|
||||||
|
|
||||||
|
|
||||||
|
# === Админка для ConfigurableProduct ===
|
||||||
|
|
||||||
|
class ConfigurableProductOptionInline(admin.TabularInline):
|
||||||
|
"""Инлайн для вариантов вариативного товара"""
|
||||||
|
model = ConfigurableProductOption
|
||||||
|
extra = 0
|
||||||
|
fields = ('kit', 'product', 'variant_sku', 'is_default', 'attributes')
|
||||||
|
readonly_fields = ('variant_sku',)
|
||||||
|
verbose_name = "Вариант"
|
||||||
|
verbose_name_plural = "Варианты"
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigurableProductAttributeInline(admin.TabularInline):
|
||||||
|
"""Инлайн для атрибутов родительского товара"""
|
||||||
|
model = ConfigurableProductAttribute
|
||||||
|
extra = 0
|
||||||
|
fields = ('name', 'option', 'kit', 'product', 'position', 'visible')
|
||||||
|
verbose_name = "Атрибут"
|
||||||
|
verbose_name_plural = "Атрибуты"
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(ConfigurableProduct)
|
||||||
|
class ConfigurableProductAdmin(admin.ModelAdmin):
|
||||||
|
"""Админка для вариативных товаров"""
|
||||||
|
list_display = ('name', 'sku', 'status', 'get_options_count', 'created_at')
|
||||||
|
list_filter = ('status', 'created_at')
|
||||||
|
search_fields = ('name', 'sku', 'description')
|
||||||
|
readonly_fields = ('created_at', 'updated_at', 'slug')
|
||||||
|
inlines = [ConfigurableProductOptionInline, ConfigurableProductAttributeInline]
|
||||||
|
|
||||||
|
fieldsets = (
|
||||||
|
('Основная информация', {
|
||||||
|
'fields': ('name', 'sku', 'slug', 'status')
|
||||||
|
}),
|
||||||
|
('Описание', {
|
||||||
|
'fields': ('short_description', 'description')
|
||||||
|
}),
|
||||||
|
('Служебная информация', {
|
||||||
|
'fields': ('created_at', 'updated_at'),
|
||||||
|
'classes': ('collapse',)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_options_count(self, obj):
|
||||||
|
"""Количество вариантов"""
|
||||||
|
count = obj.options.count()
|
||||||
|
return format_html(
|
||||||
|
'<span style="font-weight: bold; color: {};">{}</span>',
|
||||||
|
'#28a745' if count > 0 else '#6c757d',
|
||||||
|
count
|
||||||
|
)
|
||||||
|
get_options_count.short_description = 'Вариантов'
|
||||||
|
|||||||
Reference in New Issue
Block a user