193 lines
5.7 KiB
Python
193 lines
5.7 KiB
Python
from django.contrib import admin
|
|
from .models import *
|
|
from unfold.admin import ModelAdmin, TabularInline, StackedInline
|
|
|
|
from import_export.admin import ImportExportModelAdmin
|
|
from unfold.contrib.import_export.forms import ExportForm, ImportForm, SelectableFieldsExportForm
|
|
from unfold.contrib.forms.widgets import ArrayWidget, WysiwygWidget
|
|
from django.contrib.postgres.fields import ArrayField
|
|
from unfold.widgets import (
|
|
UnfoldAdminColorInputWidget,
|
|
)
|
|
from unfold.decorators import action, display
|
|
|
|
@admin.register(InPackItems)
|
|
class InPackItemsAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
search_fields = ['item_title']
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
class InStuckColorsInLine(TabularInline):
|
|
model = InStuckColors
|
|
extra = 0
|
|
tab = True
|
|
formfield_overrides = {
|
|
models.CharField: {"widget": UnfoldAdminColorInputWidget()},
|
|
}
|
|
verbose_name = 'رنگ موجود'
|
|
verbose_name_plural = 'رنگهای موجود'
|
|
|
|
|
|
@admin.register(DetailModel)
|
|
class DetailModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
search_fields = ['title']
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
class DetailModelInLine(StackedInline):
|
|
model = ProductDetailModel
|
|
extra = 0
|
|
tab = True
|
|
autocomplete_fields = ['detail']
|
|
verbose_name = 'جزئیات محصول'
|
|
verbose_name_plural = 'جزئیات محصول'
|
|
|
|
@admin.register(ProductModel)
|
|
class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
inlines = [InStuckColorsInLine, DetailModelInLine]
|
|
readonly_fields = ('slug', )
|
|
search_fields = ['name', 'description', ]
|
|
list_filter = ['currency', 'show', 'category']
|
|
autocomplete_fields = ['related_products', 'in_pack_items']
|
|
# compressed_fields = True
|
|
warn_unsaved_form = True
|
|
list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'discount', 'sell']
|
|
fieldsets = (
|
|
('فیلد های اصلی', {'fields': ('name', 'description', 'price', 'min_price', 'currency', 'discount', 'category', 'related_products', 'show',), "classes": ["tab"],}),
|
|
('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
|
|
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view', 'sell', ), "classes": ["tab"],}),
|
|
('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],})
|
|
|
|
)
|
|
formfield_overrides = {
|
|
models.TextField: {
|
|
"widget": WysiwygWidget,
|
|
},
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
|
|
def display_price(self, obj):
|
|
return obj.get_toman_price()
|
|
display_price.short_description = 'قیمت تومانی'
|
|
|
|
@display(description='محصول', header=True)
|
|
def display_image(self, instance):
|
|
if instance.image1:
|
|
return [
|
|
instance.name,
|
|
None,
|
|
None,
|
|
{
|
|
"path": instance.image1.url,
|
|
"height": 30,
|
|
"width": 30,
|
|
"borderless": True,
|
|
# "squared": True,
|
|
},
|
|
]
|
|
return ('خالی',)
|
|
# @display(
|
|
# description=("نمایش در صفحه ی اصلی"),
|
|
# label={
|
|
# True: "danger",
|
|
# False: "success",
|
|
# },
|
|
# )
|
|
# def display_show(self, instance):
|
|
# return instance.show
|
|
|
|
|
|
@admin.register(MainCategoryModel)
|
|
class MainCategoryModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
list_display = ['name', ]
|
|
readonly_fields = ('slug', )
|
|
search_fields = ['name', 'slug']
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
|
|
@admin.register(SubCategoryModel)
|
|
class SubCategoryModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
list_display = ['name', 'parent', 'show']
|
|
|
|
search_fields = ['name', 'slug']
|
|
list_filter = ['parent', 'show', ]
|
|
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
|
|
readonly_fields = ('slug', )
|
|
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
|
|
@admin.register(CommentModel)
|
|
class CommentAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
list_display = ['user', 'product', 'display_content','show']
|
|
search_fields = ['content',]
|
|
list_filter = ['show',]
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
def display_content(self, obj):
|
|
return obj.content[0:20] + '...'
|
|
display_content.short_description = 'محتوای کامنت'
|
|
|
|
@admin.register(DollorModel)
|
|
class DollorAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
|
|
exclude = ('unique_filed', )
|
|
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
readonly_fields = ('price',) |