i hope database wont get fcked
dynamic fields for product
This commit is contained in:
+73
-12
@@ -11,6 +11,20 @@ from unfold.widgets import (
|
||||
)
|
||||
from unfold.decorators import action, display
|
||||
|
||||
@admin.register(ProductDetailCategory)
|
||||
class ProductDetailCategoryAdmin(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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@admin.register(InPackItems)
|
||||
class InPackItemsAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
@@ -24,15 +38,61 @@ class InPackItemsAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
"widget": ArrayWidget,
|
||||
}
|
||||
}
|
||||
class InStuckColorsInLine(TabularInline):
|
||||
model = InStuckColors
|
||||
extra = 0
|
||||
tab = True
|
||||
|
||||
|
||||
@admin.register(AttributeType)
|
||||
class AttributeTypeAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
export_form_class = ExportForm
|
||||
search_fields = ['name']
|
||||
compressed_fields = True
|
||||
warn_unsaved_form = True
|
||||
|
||||
formfield_overrides = {
|
||||
models.CharField: {"widget": UnfoldAdminColorInputWidget()},
|
||||
ArrayField: {
|
||||
"widget": ArrayWidget,
|
||||
}
|
||||
}
|
||||
verbose_name = 'رنگ موجود'
|
||||
verbose_name_plural = 'رنگهای موجود'
|
||||
|
||||
|
||||
@admin.register(AttributeValue)
|
||||
class AttributeValueAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
export_form_class = ExportForm
|
||||
search_fields = ['value']
|
||||
compressed_fields = True
|
||||
warn_unsaved_form = True
|
||||
|
||||
formfield_overrides = {
|
||||
ArrayField: {
|
||||
"widget": ArrayWidget,
|
||||
}
|
||||
}
|
||||
def get_form(self, request, obj=None, change=False, **kwargs):
|
||||
form = super().get_form(request, obj, change, **kwargs)
|
||||
form.base_fields["color"].widget = UnfoldAdminColorInputWidget()
|
||||
return form
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ProductVariantInLine(StackedInline):
|
||||
model = ProductVariant
|
||||
extra = 0
|
||||
show_change_link = True
|
||||
tab = True
|
||||
|
||||
autocomplete_fields = ['attributes']
|
||||
# search_fields = ['']
|
||||
|
||||
|
||||
def get_form(self, request, obj=None, change=False, **kwargs):
|
||||
form = super().get_form(request, obj, change, **kwargs)
|
||||
form.base_fields["color"].widget = UnfoldAdminColorInputWidget()
|
||||
return form
|
||||
|
||||
|
||||
|
||||
|
||||
@admin.register(DetailModel)
|
||||
@@ -55,20 +115,21 @@ class DetailModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
class DetailModelInLine(StackedInline):
|
||||
model = ProductDetailModel
|
||||
extra = 0
|
||||
show_change_link = True
|
||||
tab = True
|
||||
autocomplete_fields = ['detail']
|
||||
verbose_name = 'جزئیات محصول'
|
||||
verbose_name_plural = 'جزئیات محصول'
|
||||
autocomplete_fields = ['detail', 'detail_category']
|
||||
|
||||
|
||||
|
||||
@admin.register(ProductModel)
|
||||
class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
export_form_class = ExportForm
|
||||
inlines = [InStuckColorsInLine, DetailModelInLine]
|
||||
inlines = [ProductVariantInLine, DetailModelInLine]
|
||||
readonly_fields = ('slug', )
|
||||
search_fields = ['name', 'description', ]
|
||||
list_filter = ['currency', 'show', 'category']
|
||||
autocomplete_fields = ['related_products', 'in_pack_items']
|
||||
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']
|
||||
|
||||
Reference in New Issue
Block a user