def add_problem_from_xls(cls, lists): from models.subject import Subject from models.chapter import Chapter subject = Subject.new({ "name": lists[0][0], }) chapter_id_flag = -1 chapter_id = -1 for item in lists: if int(item[1]) != chapter_id_flag: chapter = Chapter.new({ 'subject_id': subject.id, 'name': item[2] }) chapter_id = chapter.id chapter_id_flag = int(item[1]) cls.add_problem(subject.id, chapter_id, item)