135 lines
3.8 KiB
Python
135 lines
3.8 KiB
Python
from django.contrib import admin
|
|
from .models import *
|
|
from unfold.admin import ModelAdmin, TabularInline
|
|
|
|
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
|
|
class InStuckColorsInLine(TabularInline):
|
|
model = InStuckColors
|
|
extra = 0
|
|
tab = True
|
|
formfield_overrides = {
|
|
models.CharField: {"widget": UnfoldAdminColorInputWidget()},
|
|
}
|
|
|
|
@admin.register(ProductModel)
|
|
class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
import_form_class = ImportForm
|
|
export_form_class = ExportForm
|
|
inlines = [InStuckColorsInLine]
|
|
readonly_fields = ('slug', )
|
|
search_fields = ['name']
|
|
autocomplete_fields = ['related_products']
|
|
# compressed_fields = True
|
|
warn_unsaved_form = True
|
|
list_display = ['display_image', 'price',]
|
|
fieldsets = (
|
|
('Main Fileds', {'fields': ('name', 'description', 'price', 'min_price', 'currency', 'discount', 'category', 'related_products', 'show',), "classes": ["tab"],}),
|
|
('SEO Fileds', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
|
|
('Users Fileds', {'fields': ('rating', 'view', 'sell', ), "classes": ["tab"],})
|
|
|
|
)
|
|
formfield_overrides = {
|
|
models.TextField: {
|
|
"widget": WysiwygWidget,
|
|
},
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
@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
|
|
|
|
readonly_fields = ('slug', )
|
|
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
|
|
@admin.register(SubCategoryModel)
|
|
class SubCategoryModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
|
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
|
|
|
|
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
formfield_overrides = {
|
|
ArrayField: {
|
|
"widget": ArrayWidget,
|
|
}
|
|
}
|
|
|
|
@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',) |