Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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