def add_group(name): gr = Group.select().where(Group.groupname == name) if len(gr) == 0: row = Group(groupname=name) row.save() req = (f'Создана группа {name}') return req else: req = (f'Группа {name} уже создана') return req
def find_all_groups(): sel = (Group.select( Group.groupname, Group.id, pw.fn.concat_ws(' ', Student.surname, Student.firstname, Student.secondname).alias('fio')).join( Student, pw.JOIN.LEFT_OUTER, on=(Student.id == Group.starosta_id)).order_by( Group.groupname).namedtuples()) gr = [] i = 1 for group in sel: gr.append({ 'id': group.id, 'ind': i, 'idradio': f'radio-{i-1}', 'grname': group.groupname, 'star': f'{group.fio}' if group.fio != '' else 'не указан' }) i = i + 1 return gr