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.
135 lines
4.1 KiB
135 lines
4.1 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(CartModel)
|
|
class CartModelAdmin(admin.ModelAdmin):
|
|
list_display = ('cart_id', 'profile', 'items', 'weight', 'total')
|
|
|
|
# class CartModel(models.Model):
|
|
# cart_id = models.CharField('Сессия', max_length=256, default='')
|
|
# profile = models.ForeignKey(Profile, default=None, null=True, blank=False,
|
|
# related_name='carts')
|
|
# items = models.TextField('Товары', default='')
|
|
# weight = models.CharField('Вес', max_length=20, default='0')
|
|
# total = models.CharField('Итого тенге', max_length=20, default='0')
|
|
|
|
# @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', 'delivery_date']
|
|
search_fields = ['variation', 'article']
|
|
list_filter = ['discount', ]
|
|
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ('title', 'is_leader', 'priority', 'on_main')
|
|
list_editable = ('is_leader', 'priority', 'on_main')
|
|
search_fields = ('title', 'slug')
|
|
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', 'deliv_service', 'city', 'kazpost_city', 'address', 'deliv_type', 'amount', 'status',
|
|
get_order_items)
|
|
|
|
|
|
@admin.register(ProductFeedback)
|
|
class ProductFeedbackAdmin(admin.ModelAdmin):
|
|
list_display = ('created', 'product', 'name', 'email', 'text', 'stars')
|
|
|
|
#
|
|
# @admin.register(Category)
|
|
# class CategoryAdmin(admin.ModelAdmin):
|
|
# list_display = ('title',)
|
|
#
|
|
# @admin.register(Dog)
|
|
# class DogAdmin(admin.ModelAdmin):
|
|
# list_display = ('name', 'data')
|
|
#
|
|
|