MCPcopy
hub / github.com/django/django / get_field

Method get_field

django/db/models/options.py:670–695  ·  view source on GitHub ↗

Return a field instance given the name of a forward or reverse field.

(self, field_name)

Source from the content-addressed store, hash-verified

668 return res
669
670 def get_field(self, field_name):
671 """
672 Return a field instance given the name of a forward or reverse field.
673 """
674 try:
675 # In order to avoid premature loading of the relation tree
676 # (expensive) we prefer checking if the field is a forward field.
677 return self._forward_fields_map[field_name]
678 except KeyError:
679 # If the app registry is not ready, reverse fields are
680 # unavailable, therefore we throw a FieldDoesNotExist exception.
681 if not self.apps.models_ready:
682 raise FieldDoesNotExist(
683 "%s has no field named '%s'. The app cache isn't ready yet, "
684 "so if this is an auto-created related field, it won't "
685 "be available yet." % (self.object_name, field_name)
686 )
687
688 try:
689 # Retrieve field instance by name from cached or just-computed
690 # field map.
691 return self.fields_map[field_name]
692 except KeyError:
693 raise FieldDoesNotExist(
694 "%s has no field named '%s'" % (self.object_name, field_name)
695 )
696
697 def get_base_chain(self, model):
698 """

Callers 15

_check_field_nameMethod · 0.45
_get_field_nameMethod · 0.45
__init__Method · 0.45
validateMethod · 0.45
_add_viewMethod · 0.45
check_user_modelFunction · 0.45
check_models_permissionsFunction · 0.45
get_default_usernameFunction · 0.45
__init__Method · 0.45
add_argumentsMethod · 0.45
handleMethod · 0.45
constraint_sqlMethod · 0.45

Calls 1

FieldDoesNotExistClass · 0.90

Tested by

no test coverage detected