есть бд со следующей структурой:
from sqlobject import * from sqlobject.sqlbuilder import EXISTS, Select from datetime import datetime import time class Customer(SQLObject): name = UnicodeCol() city = ForeignKey("City") Rating = IntCol() salespeople = ForeignKey("SalesPeople") orders = MultipleJoin("Order1") class Order1(SQLObject): Amt = FloatCol() Odate = DateTimeCol() salespeople = ForeignKey("SalesPeople") customer = ForeignKey("Customer") class SalesPeople(SQLObject): name=UnicodeCol() comm = FloatCol() city = ForeignKey("City") customers = MultipleJoin("Customer", joinColumn="salespeople_id") orders = MultipleJoin("Order1") class City(SQLObject): name = UnicodeCol() customers = MultipleJoin("Customer", joinColumn="city_id") peoples = MultipleJoin("SalesPeople", joinColumn="city_id") connection_string = "postgres://user:11111111@localhost:5432/test1" connection = connectionForURI(connection_string) sqlhub.processConnection = connection
подскажите, пожалуйста, как упростить ниже описанный запрос?
def select9_1(list1): prev=None for order in list1: if prev==None: pass elif (prev-time.mktime(order.Odate.timetuple()))<=172800.0: return True prev = time.mktime(order.Odate.timetuple()) return False def select9(): k = 0 for cus in Customer.select(): if select9_1(cus.orders): k+=1 print cus.name print "k = ", k