INSERT INTO test_employee (SELECT * FROM objectid INNER JOIN
( SELECT personnelnumber, MAX(objectid ) AS MAX_REQUEST FROM employee GROUP BY personnelnumber) AS M
ON M.personnelnumber = employee.personnelnumber AND M.MAX_REQUEST = employee.objectid )
optionList += '<li class="review-page--line-item" data-code="$SPT31"><span class="label--option">' +
($('.option-btn.is-selected').find('.group--options_checkbox--name')).text() + '</span></li>'
class ProductAdvantage(BaseModel):
"""Преимущества в карточке продукта"""
icon = models.FileField(
_('Иконка'), blank=True, null=True, max_length=255, upload_to='img/advantages'
)
title = models.CharField(_('Заголовок'), max_length=255, blank=True, null=True)
subtitle = models.CharField(_('Подзаголовок'), max_length=255, blank=True, null=True)
translation_fields = ('title', 'subtitle')
def __str__(self):
return self.title
class Meta:
verbose_name = _('Преимущество')
verbose_name_plural = _('Преимущества в карточке продукта')
class Product(ImageMixin, BaseModel):
"""Продукт"""
title = models.CharField(_('Наименование'), max_length=255, db_index=True)
slug = models.SlugField(
_('Алиас'), max_length=150, db_index=True, unique=True,
help_text=_('Латинские буквы и цифры')
)
sku = models.CharField(
_('Артикул'), max_length=255, blank=True, null=True, db_index=True, unique=True
)
image = ImageCropField(
_('Главное изображение'), max_length=255, upload_to='img/image/products', blank=True, null=True
)
thumb_images = ImageRatioField(
'image', size='555x445', verbose_name=_('Отображаемое изображение')
)
price = models.DecimalField(
_('Цена'), max_digits=10, decimal_places=2, blank=True, null=False, default=Decimal('0')
)
discount_price = models.DecimalField(
_('Цена со скидкой'), max_digits=10, decimal_places=2, blank=True, null=False, default=Decimal('0')
)
short_description = models.TextField(
_('Короткое описание'), blank=True, null=True, help_text=_('Отображается в карточке товара')
)
body = RichTextUploadingField(_('Основной контент'), blank=True, null=False)
manufacturer = models.ForeignKey(
Manufacturer, related_name='products', verbose_name=_('Производитель'),
blank=True, null=True, on_delete=None
)
is_balance = models.BooleanField(_('В наличии'), default=True)
advantages = models.ManyToManyField(
ProductAdvantage, verbose_name=_('Преимущества'), related_name='products', blank=True
)
categories = models.ManyToManyField(
ProductCategory, verbose_name=_('Категории'), related_name='products',
blank=True
)
related_products = models.ManyToManyField(
'self', verbose_name=_('Связанные товары'), symmetrical=True
)
translation_fields = ('title', 'body', 'short_description')
class Meta:
verbose_name = _('Продукт')
verbose_name_plural = _('Продукты')
def __str__(self):
return self.title
def get_absolute_url(self, lang=settings.DEFAULT_LANGUAGE):
return reverse('catalog:product', kwargs={
'lang': lang,
'slug': self.slug
})
class Feature(BaseModel):
"""Характеристика"""
title = models.CharField(_('Заголовок'), max_length=255, unique=True)
translation_fields = ('title',)
class Meta:
verbose_name = _('Характеристика')
verbose_name_plural = _('Характеристики')
def __str__(self):
return self.title
class ProductFeature(BaseModel):
"""Характеристики товара"""
product = models.ForeignKey(
Product, verbose_name=_('Товар'), related_name='features', on_delete=None
)
feature = models.ForeignKey(
Feature, related_name='product_features', verbose_name=_('Характеристика'), on_delete=None
)
value = models.CharField(_('Значение'), max_length=255)
hint = models.CharField(_('Подсказка'), max_length=255, blank=True, null=True)
translation_fields = ('value', 'hint')
class Meta:
verbose_name = _('Характеристика товара')
verbose_name_plural = _('Характеристики товара')
def __str__(self):
return '%s: %s' % (self.feature, self.value)
class ProductFeatureMain(BaseModel):
"""Главные характеристики товара"""
product = models.ForeignKey(
Product, verbose_name=_('Товар'), related_name='features_main', on_delete=None
)
feature = models.ForeignKey(
Feature, related_name='product_features_main', verbose_name=_('Характеристика'), on_delete=None
)
value = models.CharField(_('Значение'), max_length=255)
hint = models.CharField(_('Подсказка'), max_length=255, blank=True, null=True)
translation_fields = ('value', 'hint')
class Meta:
verbose_name = _('Главная характеристика товара')
verbose_name_plural = _('Главные характеристики товара')
def __str__(self):
return '%s: %s' % (self.feature, self.value)
class ProductImage(ImageMixin, BaseModel):
"""Изображения продукта"""
product = models.ForeignKey(
Product, verbose_name=_('Продукт'), related_name='images', on_delete=None
)
image = ImageCropField(_('Изображение'), max_length=255, upload_to='img/image/products/images')
thumb_images = ImageRatioField(
'image', size='555x445', verbose_name=_('Обрезка полей'), allow_fullsize=True,
free_crop=True
)
alt = models.CharField(
_('Подпись (alt)'), max_length=255, blank=True, null=True,
help_text=_('Альтернативный текст вместо изображения')
)
translation_fields = ('alt',)
def __str__(self):
return str(self.pk)
class Meta:
verbose_name = _('Изображение продукта')
verbose_name_plural = _('Изображения продукта')
class BaseProductFeatureInline(TranslationTabularInline):
"""Характеристики продукта"""
extra = 0
readonly_fields = ('created', 'updated')
suit_classes = 'suit-tab suit-tab-features'
class ProductFeatureInline(BaseProductFeatureInline):
"""Характеристики продукта"""
fields = models.ProductFeature().collect_fields()
model = models.ProductFeature
class ProductFeatureMainInline(BaseProductFeatureInline):
"""Главные характеристики продукта"""
fields = models.ProductFeatureMain().collect_fields()
model = models.ProductFeatureMain
class ProductImageMainInline(ImageCroppingMixin, TranslationTabularInline):
"""Изображения продукта"""
extra = 0
fields = models.ProductImage().collect_fields()
model = models.ProductImage
readonly_fields = ('created', 'updated')
suit_classes = 'suit-tab suit-tab-images'
@admin.register(models.ProductAdvantage)
class ProductAdvantageAdmin(BaseModelAdmin, TranslationAdmin):
"""Преимущества"""
fields = models.ProductAdvantage().collect_fields()
list_display = ('id', 'title', 'ordering', 'status', 'updated')
list_display_links = ('id', 'title')
ordering = BaseModelAdmin.ordering + ('title',)
search_fields = ['=id', 'title'] + get_model_translation_fields(models.ProductAdvantage)
class Media:
js = ('admin/js/translit.js',)
class ProductRelatedInline(TabularInline):
"""Связанные продукты"""
extra = 0
raw_id_fields = ('to_product',)
fk_name = 'from_product'
model = models.Product.related_products.through
suit_classes = 'suit-tab suit-tab-related'
verbose_name = _('Связанный продукт')
verbose_name_plural = _('Связанные продукты')
class ProductCategoriesInline(TabularInline):
"""Категории продукта"""
extra = 0
model = models.Product.categories.through
suit_classes = 'suit-tab suit-tab-categories'
verbose_name = _('Категория')
verbose_name_plural = _('Категории')
class ProductAdvantageInline(TabularInline):
"""Категории продукта"""
extra = 0
model = models.Product.advantages.through
suit_classes = 'suit-tab suit-tab-advantages'
verbose_name = _('Преимущество')
verbose_name_plural = _('Преимущества')
@admin.register(models.Product)
class ProductAdmin(ModelTranlsationFieldsetsMixin, ImageCroppingMixin, TranslationAdmin, BaseModelAdmin):
"""Продукты"""
group_fieldsets = True
inlines = (
ProductCategoriesInline, ProductImageMainInline, ProductFeatureMainInline, ProductFeatureInline,
ProductRelatedInline, ProductAdvantageInline
)
list_display = ('id', 'image_thumb', 'title', 'price', 'ordering', 'status', 'updated')
list_display_links = ('id', 'image_thumb', 'title')
list_editable = ('price', 'ordering', 'status')
list_filter = BaseModelAdmin.list_filter + ('categories', 'manufacturer')
ordering = BaseModelAdmin.ordering + ('title',)
save_as = True
search_fields = ['=id', 'slug', 'image'] + get_model_translation_fields(models.Product)
suit_form_tabs = (
('general', _('Основное')),
('body', _('Основной контент')),
('categories', _('Категории')),
('advantages', _('Преимущества')),
('images', _('Изображения')),
('related', _('Связанные продукты')),
('features', _('Характеристики')),
)
tabs_mapping = {
'': 'general',
# 'Наименование': 'general',
'Основной контент': 'body',
'Короткое описание': 'body',
'Контент вкладки "характеристики"': 'features'
}
class Media:
js = ('admin/js/translit.js',)