Я использую новейшую пониму на Python 3.6.
Я хочу сделать некоторые обезьяны-патчи для классов сущностей, созданных на другом этапе (чтобы добавить вычисляемые поля).
Есть ли шанс, что я смогу получить список типов сущностей, доступных из объекта db?
В моем файле models.py:
from pony.orm import *
db = Database()
class OneEntity(db.Entity):
id = PrimaryKey(int, auto=True)
nom = Required(str)
class AnotherEntity(db.Entity):
id = PrimaryKey(int, auto=True)
someprop = Required(str)
В другом файле:
from models import *
db.bind(provider='sqlite', filename = 'test.db', create_db = True)
db.generate_mapping(create_tables = True)
def say_hello():
""" some dummy proc to monkey patch onto entity classes"""
print("hello")
#This works, but isn't workable for my use case (too many entity classes)
OneEntity.monkey_patched_method = say_hello
#And here I'd like to have the ability to list entity classes programmatically
for Entity in some_code_that_i_dont_know :
Entity.new_method = say_hello