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)
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()
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()
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()
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( ) # Убираем из каталога неактивные продукты
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
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"
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()
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()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['product'].queryset = Product.get_items()
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])
def same_products(hot_product): return Product.get_items().filter(category=hot_product.category). \ exclude(pk=hot_product.pk)[:4]
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) print(Product.get_items().query) self.fields['product'].queryset = Product.get_items().select_related( 'category')