当孩子们准备好了,怎么做?

2024-04-25 09:52:25 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑下面的一对多模型。

class Person(Base):
    id
    things = relationship('Thing')

    def some_magic_here():
        pass
class Thing(Base):
    id
    person_id = ForeignKey(person.id)

我想要实现的是,当我做以下事情时:

p = Person()
thing1 = Thing()
thing2 = Thing()
p.things = [thing1, thing2]

方法some_magic_here将在将thing1和thing2作为子对象添加之前执行一些处理工作


Tags: 模型idbaseheredefmagicsomeclass