Add utilities for iterating through model fields and reverse relations.
Review Request #12231 — Created April 8, 2022 and submitted
This introduces the following new functions in
walk_model_tree(): Iterates through a model an all of its parents.
get_model_rel_tree(): Builds and returns a cached dictionary mapping
table names to reverse relations.
clear_model_rel_tree(): Clears the cached relation tree state.
iter_model_fields(): Iterates through fields on a model, yielding
fields based on the provided criteria.
iter_non_m2m_reverse_relations():Iterate through all actual reverse
relation fields that point to another field (excluding
ManyToManyFieldfields but including fields on their "through"
Each of these are basically equivalent to functionality internal to
modern versions of Django, but lacking any equivalents in earlier
versions. They'll be crucial for upcoming work on field type changes.
Unit tests pass on all supported versions of Django.
Made use of this new functionality in the in-progress field type changes.
F401 'django.db.models.fields.related' imported but unused