Есть две таблицы:
Admin_list:
class Admin_list(Base):
__tablename__ = 'admin_list'
admin_id: Mapped[int] = mapped_column(Integer, unique=True, nullable=False, primary_key=True)
user_id: Mapped[str] = mapped_column(String, unique=True, nullable=False)
date: Mapped[datetime] = mapped_column(DateTime(timezone=False), unique=False, nullable=False)
admin_worked: Mapped['Admin_work'] = relationship(back_populates='admin_lists', cascade='all, delete-orphan')
class Admin_work(Base):
__tablename__ = 'admin_work'
admin_work_id: Mapped[int] = mapped_column(BIGINT, unique=True, nullable=False, primary_key=True)
type_work: Mapped[str] = mapped_column(String, unique=False, nullable=False)
callback_data: Mapped[str] = mapped_column(String, unique=False, nullable=False)
admin_id: Mapped[int] = mapped_column(ForeignKey('admin_list.admin_id'))
admin_lists: Mapped["Admin_list"] = relationship(back_populates='admin_worked')
Я пытаюсь написать следующее:
async def fixing_work_admin(admin_id_work, callback_data):
async with session_maker() as session:
stmt = select(Admin_list).where(
Admin_list.user_id == str(admin_id_work))
admin_stmt = await session.execute(stmt)
add_work: Admin_list | None = admin_stmt.first()
add_work.admin_worked = [Admin_work(type_work='Registration', callback_data=callback_data)]
await session.commit()
Получается вот такая ошибка:
raise AttributeError("can't set attribute")
AttributeError: can't set attribute
Ругается на add_work.admin_worked = [Admin_work(type_work = 'Registration', callback_data = callback_data)]. Что не так?