AttributeError: 'NoneType' object has no attribute 'Gender_Id'. Что здесь можно исправить?
https://disk.yandex.ru/d/8p15G_H359Q4Yw
Ошибка:
Traceback (most recent call last):
File "e:\Учеба\Учеба\8 семестр\Диплом\PuthonPrograms\main.py", line 206, in on_btnEdit_click
dialog = UpdateDialog(self.gender, self.status, init_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Учеба\Учеба\8 семестр\Диплом\PuthonPrograms\main.py", line 146, in __init__
Gender_Name = gender[init_data.Gender_Id].Name
^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'Gender_Id'
Код с 19 по 102:
class ItemsModel(QtCore.QAbstractTableModel):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.items = []
self.gender = {}
self.status = {}
def setItems(self, items):
self.beginResetModel()
self.items = items
self.endResetModel()
def setGender(self, gender):
self.beginResetModel()
self.gender = gender
self.endResetModel()
def setStatus(self, status):
self.beginResetModel()
self.status = status
self.endResetModel()
def rowCount(self, *args, **kwargs) -> int:
return len(self.items)
def columnCount(self, *args, **kwargs) -> int:
return 11
def data(self, index: QtCore.QModelIndex, role: QtCore.Qt.ItemDataRole):
if not index.isValid():
return
if role == QtCore.Qt.ItemDataRole.DisplayRole:
General_information_info = self.items[index.row()]
col = index.column()
if col == 0:
return f'{General_information_info.NumRoom}'
elif col == 1:
Status_title = self.status[General_information_info.Status_Id].Name
return Status_title
elif col == 2:
return f'{General_information_info.Surname}'
elif col == 3:
return f'{General_information_info.Name}'
elif col == 4:
return f'{General_information_info.MidName}'
elif col == 5:
return f'{General_information_info.PhoneNum}'
elif col == 6:
return f'{General_information_info.Date}'
elif col == 7:
return f'{General_information_info.SumPay}'
elif col == 8:
return f'{General_information_info.Introduced}'
elif col == 9:
return f'{General_information_info.Remains}'
elif col == 10:
Gender_title = self.gender[General_information_info.Gender_Id].Name
return Gender_title
elif role == QtCore.Qt.ItemDataRole.UserRole:
return self.items[index.row()]
def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role: QtCore.Qt.ItemDataRole):
"NumRoom, Status_Id, Surname, Name, MidName, PhoneNum, Date, SumPay, Introduced, Remains, Gender_Id"
if role == QtCore.Qt.ItemDataRole.DisplayRole:
if orientation == QtCore.Qt.Orientation.Horizontal:
return {
0: "Комната",
1: "Статус оплаты",
2: "Фамилия",
3: "Имя",
4: "Отчество",
5: "Телефон",
6: "Дата рождения",
7: "Сумма",
8: "Внесено",
9: "Отстаток",
10: "Пол",
}.get(section)
Код 146-147:
Gender_Name = gender[init_data.Gender_Id].Name
self.ui.cmbGender.setCurrentText(Gender_Name)
Код 202-209
def on_btnEdit_click(self):
item = self.ui.tblItems.currentIndex()
init_data = item.data(QtCore.Qt.ItemDataRole.UserRole)
dialog = UpdateDialog(self.gender, self.status, init_data)
r = dialog.exec()
if r == 0:
return