Epic: Fix up all FKs and related names to follow a self-consistent pattern
See original GitHub issueProposed Changes
We don’t have a single consistent pattern for foreign key names and (especially) related names on the corresponding reverse relations, for example:
Site.powerpanel_set
versusSite.rack_groups
(pluralization, underscores)PowerFeed.power_panel
versusPowerPanel.powerfeeds
(underscores)Tenant.rackreservations
versusTenant.route_targets
(underscores)
etc.
Fixing this will be a breaking change for the ORM and possibly also for the REST API and/or GraphQL as well, but it’s the right thing to do long-term.
Justification
Tech debt reduction, improved self-consistency and ease of use.
TODO
- #2960
- Do the work (to be updated upon completion of spike)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
v2.0.0 Milestone · GitHub
All GitHub issues in this milestones are only milestone-candidates and subject to ... Fix up all FKs and related names to follow a...
Read more >3 common foreign key mistakes (and how to avoid them)
Foreign key constraints are important to any SQL database, but they can also cause problems if they're not implemented correctly.
Read more >Draft: Update feature_category for those features owned by ...
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) I...
Read more >XXV DAE-BRNS High Energy Physics Symposium 2022
For the present analysis, we have taken up Golden ratio mixing pattern at high scale. This is compatible with the low energy neutrino ......
Read more >Filled Ultimum Temporum Reboot (lvl 100, epic, 3.5) CLOSED ...
A friend of mine was hoping to have this game, turned back up. ... Your character dies at negative HP's equal to 1...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My proposal as we had discussed before is to use the
Meta.verbose_name_plural
for the related model and normalize spaces to underscores. For example:… and so on.
To me this gives us determinism and consistency and makes it easy to write lint checks if we want to do so.
The only edge cases would be for m2m such as specifying a best practice for when we do not want a related name (e.g. using
related_name="+"
) or where we want an interpolated related name (e.g.related_name="foo_%(model)s_related"
).As part of this can we standardize on parent/child relation names for tree objects? django-tree-queries doesn’t give you an option to choose the names for those relationships so anything that’s a django-tree-queries
TreeNode
is already usingparent
/children
but we have inconsistencies on MPTTModels. For example InventoryItem usesparent
/child_items
and Region usesparent
/children
.