label_for_field
Return a sensible label for a field name. The name can be a callable, property (but not created with @property decorator), or the name of an object's attribute, as well as a model field, including across related objects. If return_attr is True, also return the resolved attribute (which could be a callable). This will be None if (and only if) the name refers to a field.
def label_for_field(
name: string | callable,
model: django.db.models.Model,
model_admin: django.contrib.admin.ModelAdmin = null,
return_attr: boolean = false,
form: django.forms.BaseForm = null
) - > string | tuple
Return a sensible label for a field name. The name can be a callable, property (but not created with @property decorator), or the name of an object's attribute, as well as a model field, including across related objects. If return_attr is True, also return the resolved attribute (which could be a callable). This will be None if (and only if) the name refers to a field.
Parameters
| Name | Type | Description |
|---|---|---|
| name | `string | callable` |
| model | django.db.models.Model | The Django model class used as the starting point for field and attribute lookups. |
| model_admin | django.contrib.admin.ModelAdmin = null | An optional ModelAdmin instance to check for attributes or short_description overrides. |
| return_attr | boolean = false | If True, the function returns a tuple of (label, resolved_attribute) instead of just the label. |
| form | django.forms.BaseForm = null | An optional form instance to check for field definitions if the name is not found on the model or admin. |
Returns
| Type | Description |
|---|---|
| `string | tuple` |