|
|
|
@ -5,6 +5,7 @@ from django.db.models import Count, Min, Sum |
|
|
|
from accounts.models import Profile |
|
|
|
from accounts.models import Profile |
|
|
|
from main.models import STARS_CHOICES |
|
|
|
from main.models import STARS_CHOICES |
|
|
|
from store.alemtat import alemtat_get_cities_tuple, alemtat_get_services_tuple |
|
|
|
from store.alemtat import alemtat_get_cities_tuple, alemtat_get_services_tuple |
|
|
|
|
|
|
|
from store.queryset import ProductQuerySet |
|
|
|
|
|
|
|
|
|
|
|
FIELD_TYPE_CHAR = 'char' |
|
|
|
FIELD_TYPE_CHAR = 'char' |
|
|
|
FIELD_TYPE_INT = 'int' |
|
|
|
FIELD_TYPE_INT = 'int' |
|
|
|
@ -24,6 +25,7 @@ def photo_filename(instance, filename): |
|
|
|
|
|
|
|
|
|
|
|
return 'photo_uploads/' + slugify_filename(filename) |
|
|
|
return 'photo_uploads/' + slugify_filename(filename) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CartModel(models.Model): |
|
|
|
class CartModel(models.Model): |
|
|
|
cart_id = models.CharField('Сессия', max_length=256, default='') |
|
|
|
cart_id = models.CharField('Сессия', max_length=256, default='') |
|
|
|
profile = models.ForeignKey(Profile, default=None, null=True, blank=False, |
|
|
|
profile = models.ForeignKey(Profile, default=None, null=True, blank=False, |
|
|
|
@ -32,6 +34,7 @@ class CartModel(models.Model): |
|
|
|
weight = models.CharField('Вес', max_length=20, default='0') |
|
|
|
weight = models.CharField('Вес', max_length=20, default='0') |
|
|
|
total = models.CharField('Итого тенге', max_length=20, default='0') |
|
|
|
total = models.CharField('Итого тенге', max_length=20, default='0') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Category(models.Model): |
|
|
|
class Category(models.Model): |
|
|
|
title = models.CharField('Наименование', max_length=256, default='') |
|
|
|
title = models.CharField('Наименование', max_length=256, default='') |
|
|
|
h1 = models.CharField('Заголовок h1', max_length=256, default='', null=True, blank=True) |
|
|
|
h1 = models.CharField('Заголовок h1', max_length=256, default='', null=True, blank=True) |
|
|
|
@ -98,6 +101,11 @@ class Category(models.Model): |
|
|
|
def get_childs_ordered_by_count(self): |
|
|
|
def get_childs_ordered_by_count(self): |
|
|
|
return self.childs.annotate(Count('childs')).order_by('priority') # , '-childs__count') |
|
|
|
return self.childs.annotate(Count('childs')).order_by('priority') # , '-childs__count') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_products_in_stock_order_by(self, field): |
|
|
|
|
|
|
|
queryset = Product.objects.filter(categories__in=self.get_all_childs()).sorted_in_stock_by_field(field) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Attribute(models.Model): |
|
|
|
class Attribute(models.Model): |
|
|
|
title = models.CharField('Наименование', max_length=256, default='') |
|
|
|
title = models.CharField('Наименование', max_length=256, default='') |
|
|
|
@ -187,6 +195,8 @@ class Product(models.Model): |
|
|
|
on_main = models.BooleanField('На главной', default=False) |
|
|
|
on_main = models.BooleanField('На главной', default=False) |
|
|
|
priority = models.IntegerField('Приоритет для главной', default=0) |
|
|
|
priority = models.IntegerField('Приоритет для главной', default=0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
objects = ProductQuerySet.as_manager() |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
verbose_name = 'товар' |
|
|
|
verbose_name = 'товар' |
|
|
|
verbose_name_plural = 'товары' |
|
|
|
verbose_name_plural = 'товары' |
|
|
|
@ -277,7 +287,8 @@ class ProductVariation(models.Model): |
|
|
|
# import pdb; pdb.set_trace() |
|
|
|
# import pdb; pdb.set_trace() |
|
|
|
# from django.core.mail import mail_admins |
|
|
|
# from django.core.mail import mail_admins |
|
|
|
# mail_admins('auth', '{} {}'.format(profile, self.product.brand.slug)) |
|
|
|
# mail_admins('auth', '{} {}'.format(profile, self.product.brand.slug)) |
|
|
|
if profile and profile.is_authenticated() and self.product.brand.slug in ['beuchat', 'scorpena'] and profile.sale: |
|
|
|
if profile and profile.is_authenticated() and self.product.brand.slug in ['beuchat', |
|
|
|
|
|
|
|
'scorpena'] and profile.sale: |
|
|
|
return int(self.price - (self.price / Decimal(100) * Decimal(profile.sale))) |
|
|
|
return int(self.price - (self.price / Decimal(100) * Decimal(profile.sale))) |
|
|
|
else: |
|
|
|
else: |
|
|
|
if self.discount: |
|
|
|
if self.discount: |
|
|
|
|