-
Notifications
You must be signed in to change notification settings - Fork 0
/
suggestion.py
26 lines (21 loc) · 927 Bytes
/
suggestion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from model import Product, ProductSize, Session
class SuggestionController:
def get_suggestions(self, product, session=None):
own_session = False
if not session:
session = Session()
own_session = True
bigger_sizes = (self._session
.query(Product, ProductSize)
.filter(ProductSize.smallest_id == product.id)
.filter(Product.id == ProductSize.product_id)
.all())
bigger_sizes = [product for (product, _) in bigger_sizes]
same_class = (self._session
.query(Product)
.filter(Product.product_cl_id == product.product_cl_id)
.filter(Product.product_id != product.product_id)
.all())
if own_session:
session.close()
return bigger_sizes + same_class