MCPcopy Create free account
hub / github.com/encode/django-rest-framework / build_field

Method build_field

rest_framework/serializers.py:1257–1278  ·  view source on GitHub ↗

Return a two tuple of (cls, kwargs) to build a serializer field with.

(self, field_name, info, model_class, nested_depth)

Source from the content-addressed store, hash-verified

1255 # Methods for constructing serializer fields...
1256
1257 def build_field(self, field_name, info, model_class, nested_depth):
1258 """
1259 Return a two tuple of (cls, kwargs) to build a serializer field with.
1260 """
1261 if field_name in info.fields_and_pk:
1262 model_field = info.fields_and_pk[field_name]
1263 return self.build_standard_field(field_name, model_field)
1264
1265 elif field_name in info.relations:
1266 relation_info = info.relations[field_name]
1267 if not nested_depth:
1268 return self.build_relational_field(field_name, relation_info)
1269 else:
1270 return self.build_nested_field(field_name, relation_info, nested_depth)
1271
1272 elif hasattr(model_class, field_name):
1273 return self.build_property_field(field_name, model_class)
1274
1275 elif field_name == self.url_field_name:
1276 return self.build_url_field(field_name, model_class)
1277
1278 return self.build_unknown_field(field_name, model_class)
1279
1280 def build_standard_field(self, field_name, model_field):
1281 """

Callers 1

get_fieldsMethod · 0.95

Calls 6

build_standard_fieldMethod · 0.95
build_nested_fieldMethod · 0.95
build_property_fieldMethod · 0.95
build_url_fieldMethod · 0.95
build_unknown_fieldMethod · 0.95

Tested by

no test coverage detected