|
|
|
@ -1,5 +1,6 @@ |
|
|
|
from django.contrib import admin |
|
|
|
from django.contrib import admin |
|
|
|
from django.utils.safestring import mark_safe |
|
|
|
from django.utils.safestring import mark_safe |
|
|
|
|
|
|
|
from accounts.utils import send_email |
|
|
|
from .models import * |
|
|
|
from .models import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -24,7 +25,6 @@ class BrandAdmin(admin.ModelAdmin): |
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Category) |
|
|
|
@admin.register(Category) |
|
|
|
class CategoryAdmin(admin.ModelAdmin): |
|
|
|
class CategoryAdmin(admin.ModelAdmin): |
|
|
|
|
|
|
|
|
|
|
|
def get_parent_str(object): |
|
|
|
def get_parent_str(object): |
|
|
|
return object.parent or '' |
|
|
|
return object.parent or '' |
|
|
|
|
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ class CategoryAdmin(admin.ModelAdmin): |
|
|
|
|
|
|
|
|
|
|
|
list_display = ('title', get_parent_str, 'priority') |
|
|
|
list_display = ('title', get_parent_str, 'priority') |
|
|
|
list_editable = ('priority',) |
|
|
|
list_editable = ('priority',) |
|
|
|
list_filter = ('parent__title', ) |
|
|
|
list_filter = ('parent__title',) |
|
|
|
|
|
|
|
|
|
|
|
prepopulated_fields = {"slug": ("title",)} |
|
|
|
prepopulated_fields = {"slug": ("title",)} |
|
|
|
inlines = [AttributeForCategoryInline, ] |
|
|
|
inlines = [AttributeForCategoryInline, ] |
|
|
|
@ -46,7 +46,6 @@ class AttributeAdmin(admin.ModelAdmin): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ImageInProductInline(admin.TabularInline): |
|
|
|
class ImageInProductInline(admin.TabularInline): |
|
|
|
|
|
|
|
|
|
|
|
def render_image(self, obj): |
|
|
|
def render_image(self, obj): |
|
|
|
return mark_safe("""<img src="/static/{0}" width='200' />""".format( |
|
|
|
return mark_safe("""<img src="/static/{0}" width='200' />""".format( |
|
|
|
obj.image.url)) |
|
|
|
obj.image.url)) |
|
|
|
@ -64,6 +63,7 @@ class ProductVariationInline(admin.TabularInline): |
|
|
|
fields = ['variation', 'article', 'price', 'weight', 'in_stock', 'discount'] |
|
|
|
fields = ['variation', 'article', 'price', 'weight', 'in_stock', 'discount'] |
|
|
|
extra = 1 |
|
|
|
extra = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(ProductVariation) |
|
|
|
@admin.register(ProductVariation) |
|
|
|
class ProductVariationAdmin(admin.ModelAdmin): |
|
|
|
class ProductVariationAdmin(admin.ModelAdmin): |
|
|
|
model = ProductVariation |
|
|
|
model = ProductVariation |
|
|
|
@ -79,9 +79,31 @@ class ProductAdmin(admin.ModelAdmin): |
|
|
|
inlines = [ImageInProductInline, |
|
|
|
inlines = [ImageInProductInline, |
|
|
|
ProductVariationInline, AttributesInProductInline] |
|
|
|
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) |
|
|
|
@admin.register(OrderData) |
|
|
|
class ProductAdmin(admin.ModelAdmin): |
|
|
|
class OrderAdmin(admin.ModelAdmin): |
|
|
|
list_display = ('first_name', 'last_name', 'phone', 'email', 'city', 'address', 'deliv_type', 'amount') |
|
|
|
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) |
|
|
|
# @admin.register(Category) |
|
|
|
|