예제 #1
0
def get_products_by_category(pk):
    if settings.LOW_CACHE:
        key = f'category_{pk}_products'
        products = cache.get(key)
        if products is None:
            products = Product.get_items().filter(category_id=pk)
            cache.set(key, products)
        return products
    return Product.get_items().filter(category_id=pk)
예제 #2
0
def get_products():
    if settings.LOW_CACHE:
        key = 'all_products'
        products = cache.get(key)
        if products is None:
            products = Product.get_items()
            cache.set(key, products)
        return products
    return Product.get_items()
예제 #3
0
    def __init__(self, *args, **kwargs):
        super(OrderItemForm, self).__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            field.widget.attrs['class'] = "form-control"
            field.widget.attrs['style'] = "box-sizing:border-box !important"

        self.fields['product'].queryset = Product.get_items()
예제 #4
0
파일: forms.py 프로젝트: Alex-Ruf/geekshop
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'
            field.help_text = ''

        self.fields['product'].queryset = Product.get_items().select_related()
예제 #5
0
파일: forms.py 프로젝트: adronkin/shop
    def __init__(self, *args, **kwargs):
        super(OrderItemForm, self).__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'

        self.fields['product'].queryset = Product.get_items().select_related(
        )  # Убираем из каталога неактивные продукты
예제 #6
0
    def __init__(self, *args, **kwargs):
        super(OrderItemForm, self).__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'

        # self.fields['product'].queryset = Product.get_items()
        if settings.LOW_CACHE:
            key = 'orderitemform_products'
            products = cache.get(key)
            if products is None:
                products = Product.get_items().select_related()
                cache.set(key, products)
        else:
            products = Product.get_items().select_related()

        self.fields['product'].queryset = products
예제 #7
0
 def __init__(self, *args, **kwargs):
     super(OrderItemForm, self).__init__(*args, **kwargs)
     # self.fields["product"].queryset = Product.get_items()
     super(OrderItemForm, self).__init__(*args, **kwargs)
     self.fields["product"].queryset = Product.get_items().select_related()
     for field_name, field in self.fields.items():
         field.widget.attrs["class"] = "form-control"
예제 #8
0
 def __init__(self, *args, **kwargs):
     super(OrderItemForm, self).__init__(*args, **kwargs)
     # super().__init__(*args, **kwargs)
     for field_name, field in self.fields.items():
         field.widget.attrs['class'] = 'form-control'
         # field.help_text = ''
     # Убираем неактивные продукты с формы
     # self.fields['product'].queryset = Product.get_items()
     self.fields['product'].queryset = Product.get_items().select_related()
예제 #9
0
 def __init__(self, *args, **kwargs):
     super(OrderItemForm, self).__init__(*args, **kwargs)
     for field_name, field in self.fields.items():
         field.widget.attrs['class'] = 'form-control'
     self.fields['product'].queryset = Product.get_items()
예제 #10
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.fields['product'].queryset = Product.get_items()
예제 #11
0
    def test_product_get_items(self):
        product_1 = Product.objects.get(name="стул 1")
        product_3 = Product.objects.get(name="стул 3")
        products = Product.get_items()

        self.assertEqual(list(products), [product_1, product_3])
예제 #12
0
def same_products(hot_product):
    return Product.get_items().filter(category=hot_product.category). \
               exclude(pk=hot_product.pk)[:4]
예제 #13
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     print(Product.get_items().query)
     self.fields['product'].queryset = Product.get_items().select_related(
         'category')