84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
from django.contrib import admin
|
|
|
|
from .models import Article, ArticleSection, MainProduct, SubProduct
|
|
|
|
|
|
class ArticleSectionInline(admin.TabularInline):
|
|
model = ArticleSection
|
|
extra = 1
|
|
fields = ("title", "value", "order")
|
|
ordering = ("order",)
|
|
|
|
|
|
class ArticleInline(admin.StackedInline):
|
|
model = Article
|
|
extra = 0
|
|
fields = ("title", "description", "order")
|
|
ordering = ("order",)
|
|
show_change_link = True
|
|
|
|
|
|
class SubProductInline(admin.StackedInline):
|
|
model = SubProduct
|
|
extra = 0
|
|
fields = ("name", "slug", "short_description", "image", "order", "is_active")
|
|
ordering = ("order",)
|
|
show_change_link = True
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
|
|
|
|
@admin.register(MainProduct)
|
|
class MainProductAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "order", "is_active", "created_at")
|
|
list_filter = ("is_active",)
|
|
search_fields = ("name", "description")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
list_editable = ("order", "is_active")
|
|
inlines = [SubProductInline]
|
|
fieldsets = (
|
|
(None, {"fields": ("name", "slug", "short_description", "description")}),
|
|
("Media", {"fields": ("image",)}),
|
|
("Settings", {"fields": ("order", "is_active")}),
|
|
)
|
|
|
|
|
|
@admin.register(SubProduct)
|
|
class SubProductAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "main_product", "order", "is_active", "created_at")
|
|
list_filter = ("is_active", "main_product")
|
|
search_fields = ("name", "description", "main_product__name")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
list_editable = ("order", "is_active")
|
|
raw_id_fields = ("main_product",)
|
|
inlines = [ArticleInline]
|
|
fieldsets = (
|
|
(
|
|
None,
|
|
{"fields": ("main_product", "name", "slug", "short_description", "description")},
|
|
),
|
|
("Media", {"fields": ("image",)}),
|
|
("Settings", {"fields": ("order", "is_active")}),
|
|
)
|
|
|
|
|
|
@admin.register(Article)
|
|
class ArticleAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "sub_product", "order", "created_at")
|
|
list_filter = ("sub_product__main_product",)
|
|
search_fields = ("title", "description")
|
|
list_editable = ("order",)
|
|
raw_id_fields = ("sub_product",)
|
|
inlines = [ArticleSectionInline]
|
|
fieldsets = (
|
|
(None, {"fields": ("sub_product", "title", "description")}),
|
|
("Settings", {"fields": ("order",)}),
|
|
)
|
|
|
|
|
|
@admin.register(ArticleSection)
|
|
class ArticleSectionAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "article", "order")
|
|
search_fields = ("title", "value", "article__title")
|
|
list_editable = ("order",)
|
|
raw_id_fields = ("article",)
|