def get_products_by_price(min_price): results = [] products = Product.select() for product in products: if product.price <= min_price: results.append(product) return results
def get_products_by_dimension(min_dimension): results = [] products = Product.select() for product in products: if product.dimension <= min_dimension: results.append(product) return results
def search_products(query, category): query = query.lower() products = Product.select().where(Product.name.contains(query)) if category is not None: filtered_products = [] for product in products: categories = [] category_of_product = Product.select().where( ProductCategory.product == product) for product_category in category_of_product: category_name = product_category.category.name category.append(category_name) if category in categories: filtered_products.append(product) return filtered_products return products
def get_products_by_category(category): results = [] mycategory = Category.get(name=category) products = Product.select() for product in products: for a in product.category: if a.category == mycategory: results.append(product) return results
def get_products_by_material(material): results = [] mymaterial = Material.get(name=material) products = Product.select() for product in products: for a in product.material: if a.material == mymaterial: results.append(product) return results