django_rest.py 文件源码

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

项目:apimas 作者: grnet 项目源码 文件源码
def _validate_model_type(api_field_name, model_field, django_field_type,
                         loc=()):
    """
    Checks that the type of the specified model field matches with the
    `django_field_type` passed as parameter.

    `django_field_type` may be an iterable of types. If at least one type
    matches with the type of given model field, then we have a match.
    """
    if isinstance(django_field_type, Iterable):
        matches = any(isinstance(model_field, d_field)
                      for d_field in django_field_type)
    else:
        matches = isinstance(model_field, django_field_type)
    if not matches:
        raise utils.DRFAdapterException(
            'Field {!r} is not a {!r} in your django model'.format(
                api_field_name, django_field_type), loc=loc)
    return model_field
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号