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.
116 lines
3.2 KiB
116 lines
3.2 KiB
from django.contrib import admin
|
|
from django.utils.safestring import mark_safe
|
|
from accounts.utils import send_email
|
|
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__title',)
|
|
|
|
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', 'weight', 'in_stock', 'discount']
|
|
extra = 1
|
|
|
|
|
|
@admin.register(ProductVariation)
|
|
class ProductVariationAdmin(admin.ModelAdmin):
|
|
model = ProductVariation
|
|
list_display = ['product', 'variation', 'article', 'price', 'weight', 'in_stock', 'discount']
|
|
search_fields = ['variation', 'article']
|
|
list_filter = ['discount', ]
|
|
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ('title',)
|
|
prepopulated_fields = {"slug": ("title",)}
|
|
inlines = [ImageInProductInline,
|
|
ProductVariationInline, AttributesInProductInline]
|
|
|
|
|
|
def get_order_items(obj):
|
|
retval = ''
|
|
c = 0
|
|
for o in obj.get_items():
|
|
variation, count = o[0], o[1]
|
|
c += 1
|
|
retval += '{}. {}, {}: {} шт.<br>'.format(c, variation.product.title, variation.variation, count)
|
|
return retval
|
|
|
|
|
|
get_order_items.short_description = 'Заказ'
|
|
get_order_items.allow_tags = True
|
|
|
|
|
|
@admin.register(OrderData)
|
|
class OrderAdmin(admin.ModelAdmin):
|
|
def save_model(self, request, obj, form, change):
|
|
if 'status' in form.changed_data:
|
|
if obj.status > 0:
|
|
send_email(obj.profile, template='mail/order{}.jinja'.format(obj.status), context=dict(order=obj))
|
|
obj.save()
|
|
|
|
list_display = (
|
|
'first_name', 'last_name', 'phone', 'email', 'city', 'address', 'deliv_type', 'amount', 'status', get_order_items)
|
|
|
|
#
|
|
# @admin.register(Category)
|
|
# class CategoryAdmin(admin.ModelAdmin):
|
|
# list_display = ('title',)
|
|
#
|
|
# @admin.register(Dog)
|
|
# class DogAdmin(admin.ModelAdmin):
|
|
# list_display = ('name', 'data')
|
|
#
|
|
|