Add utilities for iterating through model fields and reverse relations.

Review Request #12231 — Created April 8, 2022 and submitted

Information

Django Evolution
release-2.x

Reviewers

This introduces the following new functions in
django_evolution.utils.models:

  • 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
    ManyToManyField fields but including fields on their "through"
    tables).

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.

Summary ID
Add utilities for iterating through model fields and reverse relations.
This introduces the following new functions in `django_evolution.utils.models`: * `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 `ManyToManyField` fields but including fields on their "through" tables). 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.
8eb78c6e6610b46dd0d09232aa638121d24dca00
Description From Last Updated

F401 'django.db.models.fields.related' imported but unused

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.x (f89e7f2)