fields.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:aiopeewee 作者: kszucs 项目源码 文件源码
def get_through_model(self):
        if not self._through_model:
            lhs, rhs = self.get_models()
            tables = [model._meta.db_table for model in (lhs, rhs)]

            class Meta:
                database = self.model_class._meta.database
                db_table = '%s_%s_through' % tuple(tables)
                indexes = (
                    ((lhs._meta.name, rhs._meta.name),
                     True),)
                validate_backrefs = False

            attrs = {
                lhs._meta.name: ForeignKeyField(rel_model=lhs),
                rhs._meta.name: ForeignKeyField(rel_model=rhs)}
            attrs['Meta'] = Meta

            self._through_model = type(
                '%s%sThrough' % (lhs.__name__, rhs.__name__),
                (AioModel,),
                attrs)

        return self._through_model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号