validation.py 文件源码

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

项目:DjangoBlog 作者: 0daybug 项目源码 文件源码
def validate_readonly_fields(self, cls, model):
        " Validate that readonly_fields refers to proper attribute or field. "
        if hasattr(cls, "readonly_fields"):
            check_isseq(cls, "readonly_fields", cls.readonly_fields)
            for idx, field in enumerate(cls.readonly_fields):
                if not callable(field):
                    if not hasattr(cls, field):
                        if not hasattr(model, field):
                            try:
                                model._meta.get_field(field)
                            except FieldDoesNotExist:
                                raise ImproperlyConfigured(
                                    "%s.readonly_fields[%d], %r is not a callable or "
                                    "an attribute of %r or found in the model %r."
                                    % (cls.__name__, idx, field, cls.__name__, model._meta.object_name)
                                )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号