# models.py
class StandardModel(models.Model):
'Базовые шкафы'
title = models.CharField(max_length=200, verbose_name='Название')
article = models.CharField(max_length=10, unique=True, verbose_name='Артикул')
slug = models.SlugField(max_length=50, verbose_name='url модели')
qdoors = models.SmallIntegerField(choices=QUANTITY_DOORS, default=2, verbose_name='Количество дверей')
type_case = models.CharField(max_length=10, choices=TYPE_CASE, default='case', verbose_name='Тип корпуса')
angular = models.BooleanField(default=False, verbose_name='Угловой')
description = models.TextField(blank=True, null=True, verbose_name='Описание')
height1 = models.SmallIntegerField(default=2200, verbose_name='Высота от')
height2 = models.SmallIntegerField(default=2400, verbose_name='Высота до')
width1 = models.SmallIntegerField(default=1200, verbose_name='Ширина от')
width2 = models.SmallIntegerField(default=2000, verbose_name='Ширина до')
depth = models.SmallIntegerField(default=600, verbose_name='Глубина')
phobj = models.ForeignKey(PhotoObject, blank=True, null=True, on_delete=models.SET_NULL, verbose_name='Фотообъект')
# admin.py
@admin.register(models.StandardModel)
class StandartCasesAdmin(admin.ModelAdmin):
fieldsets = (
('Данные', {
'fields': ('title', ('article', 'slug'), 'description')
}),
('Конструктив', {
'fields': (('qdoors', 'type_case', 'angular'),)
}),
('Размеры', {
'fields': (('height1', 'height2'),
('width1', 'width2'),
'depth', ('thumb', 'phobj'))
})
)
list_display = ('thumb', 'article', 'title', 'qdoors', 'type_case', 'angular')
search_fields = ('title', 'article', 'qdoors', 'type_case', 'angular')
list_filter = ('qdoors', 'type_case', 'angular')
readonly_fields = ('thumb', )
prepopulated_fields = {'slug': ('article',)}