def get_goods(self, category_name=False, display_all=None): db = Bicycle_db() if display_all or category_name == "Всі": goods = db.edit("Select * from goods") db.close() return self.from_sqlgoods_to_dict(goods) else: if category_name is None: category_name = "Всі" category_id = db.select( 'SELECT id from categories where name like "%{}%"'.format( category_name ) ) goods = db.edit( 'Select * from goods where category like "%{}%";'.format(category_id[0]) ) db.close() return self.from_sqlgoods_to_dict(goods)
def get_category_values(self): list_dict_with_results = [] db = Bicycle_db() result = db.edit("Select * FROM categories") count = len(result) for item in result: id = item[0] name_category = item[1] parent_id = item[2] export_date = item[3] list_dict_with_results.append({ "id": id, "name_category": name_category, "parent_id": parent_id, "export_date": export_date, }) # sort_by_id return sorted(list_dict_with_results, key=lambda k: k["parent_id"])