Skip to main content

lookup_field

Retrieves a field, its attribute, and its value from a given object or model admin by resolving the provided name, which can be a field name, property, method, or lookup path.

def lookup_field(
name: str | callable,
obj: object,
model_admin: ModelAdmin | None = None
) - > tuple

Resolves a field name or callable into its corresponding field object, attribute, and value for a given model instance.

Parameters

NameTypeDescription
name`strcallable`
objobjectThe model instance from which the data is being retrieved.
model_admin`ModelAdminNone` = None

Returns

TypeDescription
tupleA triple containing (field_object, attribute, value), where field_object is the Django field instance, attribute is the resolved callable or property, and value is the actual data retrieved.