WEB-APP/ Optimization/ Build fix/ Hotkey edit mode/ Log rotation/ Form a11y/ E2E non-blocking
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class DictLikeMixin:
|
||||
"""Позволяет обращаться к ORM-объектам как к словарю.
|
||||
|
||||
Используется legacy-кодом, который мигрировал с dict-результатов asyncpg
|
||||
на ORM и не хочет переписывать все `row["field"]` / `row.get("field")`.
|
||||
"""
|
||||
|
||||
def __getitem__(self, key):
|
||||
return getattr(self, key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
return getattr(self, key, default)
|
||||
|
||||
def to_dict(self):
|
||||
return {column.name: getattr(self, column.name) for column in self.__table__.columns}
|
||||
Reference in New Issue
Block a user