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
评论列表
文章目录