You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.1 KiB
83 lines
2.1 KiB
from django.contrib import admin
|
|
from django.utils.safestring import mark_safe
|
|
from .models import *
|
|
|
|
|
|
class AttributeForCategoryInline(admin.TabularInline):
|
|
model = AttributeForCategory
|
|
|
|
|
|
class AttributesInProductInline(admin.TabularInline):
|
|
model = AttributesInProduct
|
|
|
|
|
|
@admin.register(Brand)
|
|
class BrandAdmin(admin.ModelAdmin):
|
|
list_display = ('title',)
|
|
prepopulated_fields = {"slug": ("title",)}
|
|
|
|
|
|
# @admin.register(Image)
|
|
# class ImageAdmin(admin.ModelAdmin):
|
|
# list_display = ('image',)
|
|
|
|
|
|
@admin.register(Category)
|
|
class CategoryAdmin(admin.ModelAdmin):
|
|
|
|
def get_parent_str(object):
|
|
return object.parent or ''
|
|
|
|
get_parent_str.short_description = 'Родительская категория'
|
|
get_parent_str.admin_order_field = 'parent__pk'
|
|
|
|
list_display = ('title', get_parent_str, 'priority')
|
|
list_editable = ('priority',)
|
|
list_filter = ('parent', )
|
|
|
|
prepopulated_fields = {"slug": ("title",)}
|
|
inlines = [AttributeForCategoryInline, ]
|
|
|
|
|
|
@admin.register(Attribute)
|
|
class AttributeAdmin(admin.ModelAdmin):
|
|
list_display = ('title',)
|
|
prepopulated_fields = {"slug": ("title",)}
|
|
|
|
|
|
class ImageInProductInline(admin.TabularInline):
|
|
|
|
def render_image(self, obj):
|
|
return mark_safe("""<img src="/static/{0}" width='200' />""".format(
|
|
obj.image.url))
|
|
|
|
render_image.short_description = 'Превью'
|
|
|
|
model = ImageInProduct
|
|
fields = ['render_image', 'image', 'is_main']
|
|
readonly_fields = ['render_image', ]
|
|
extra = 1
|
|
|
|
|
|
class ProductVariationInline(admin.TabularInline):
|
|
model = ProductVariation
|
|
fields = ['variation', 'article', 'price', 'in_stock']
|
|
extra = 1
|
|
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ('title',)
|
|
prepopulated_fields = {"slug": ("title",)}
|
|
inlines = [ImageInProductInline,
|
|
ProductVariationInline, AttributesInProductInline]
|
|
|
|
#
|
|
# @admin.register(Category)
|
|
# class CategoryAdmin(admin.ModelAdmin):
|
|
# list_display = ('title',)
|
|
#
|
|
# @admin.register(Dog)
|
|
# class DogAdmin(admin.ModelAdmin):
|
|
# list_display = ('name', 'data')
|
|
#
|
|
|