Skip to main content

reverse_field_path

Create a reversed field path.

E.g. Given (Order, "user__groups"),
return (Group, "user__order").

Final field must be a related model, not a data field.
def reverse_field_path(
model: Model,
path: string
) - > tuple

Create a reversed field path. E.g. Given (Order, "user__groups"), return (Group, "user__order"). Final field must be a related model, not a data field.

Parameters

NameTypeDescription
modelModelThe starting Django model class from which the field path originates
pathstringA double-underscore separated string representing the relationship traversal path to be inverted

Returns

TypeDescription
tupleA tuple containing the target model class and the string representation of the reversed lookup path