generics.py 文件源码

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

项目:django-rest-witchcraft 作者: shosca 项目源码 文件源码
def get_model(cls):
        """
        Returns the model class
        """
        model = None

        with suppress(AttributeError, InvalidRequestError):
            model = cls.queryset._only_entity_zero().class_

        if model:
            return model

        with suppress(AttributeError):
            model = cls.serializer_class.Meta.model

        assert model is not None, (
            "Couldn't figure out the model for {viewset} attribute, either provide a"
            'queryset or a serializer with a Meta.model'.format(viewset=cls.__name__)
        )

        return model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号