InlineForeignKeyField
A basic integer field that deals with validating the given value to a given parent instance in an inline.
Attributes
| Attribute | Type | Description |
|---|---|---|
| widget | [Widget](../widgets/widget.md?sid=django_forms_widgets_widget) = HiddenInput | The form widget class used to render this field, defaulting to a hidden input to store the parent relationship without user interaction. |
| default_error_messages | dict = {"invalid_choice": "The inline value did not match the parent instance."} | A dictionary containing the default error message for when the provided inline value does not match the parent instance. |
Constructor
Signature
def InlineForeignKeyField(
parent_instance: object,
*args: any,
pk_field: boolean = False,
to_field: string = None,
**kwargs: any
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| parent_instance | object | The parent model instance this field is associated with. |
| *args | any | Variable length argument list passed to the parent Field class. |
| pk_field | boolean = False | Flag indicating if this is a primary key field. |
| to_field | string = None | The specific field on the parent instance to link against. |
| **kwargs | any | Arbitrary keyword arguments passed to the parent Field class. |
Signature
def InlineForeignKeyField(
parent_instance: Model instance,
pk_field: boolean,
to_field: string
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| parent_instance | Model instance | The parent model instance that this inline field must validate against. |
| pk_field | boolean | A flag indicating if this field represents the primary key of the model. |
| to_field | string | The specific attribute name on the parent instance to use for validation instead of the primary key. |
Methods
clean()
@classmethod
def clean(
value: any
) - > Model instance
Validates that the submitted value matches the parent instance's identifier and returns the parent instance if successful.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The raw input value to be validated against the parent instance's identity. |
Returns
| Type | Description |
|---|---|
Model instance | The validated parent model instance or None if the field is a primary key field and the value is empty. |
has_changed()
@classmethod
def has_changed(
initial: any,
data: any
) - > boolean
Determines if the field value has changed, always returning False to prevent the inline foreign key from triggering change detection.
Parameters
| Name | Type | Description |
|---|---|---|
| initial | any | The initial value of the field. |
| data | any | The submitted data to compare against the initial value. |
Returns
| Type | Description |
|---|---|
boolean | Always returns False to indicate the field is considered unchanged. |