Redesign spectrum model database architecture#371
Draft
tlambert03 wants to merge 2 commits intomainfrom
Draft
Conversation
This refactoring improves the multiple nullable ForeignKey pattern for spectrum ownership with the following enhancements: **Centralization & DRY:** - Add OWNER_FIELD_CONFIG and OWNER_FIELD_NAMES constants as single source of truth for owner field configuration - Derive SpectrumForm.lookup from OWNER_FIELD_CONFIG to eliminate duplication - Add get_owner_field_name() and get_category_for_owner_field() helper methods **Database Integrity:** - Add CheckConstraint to enforce "exactly one owner" at database level - Auto-populate category field from owner type in save() method - Better validation error messages **Code Quality:** - Refactor sluglist() to use dynamic field iteration with next() - Update filter_owner() and find_similar_owners() to use constants - Add type hints to properties (owner_set, owner) - Change owner property to @cached_property for performance - Improve docstrings and add inline documentation **Documentation:** - Document rationale for multiple nullable ForeignKeys vs GenericForeignKey pattern - Add comments explaining why category field is kept despite being derivable - Reference Luke Plant's blog post for future maintainers No breaking changes - full backward compatibility maintained.
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactoring improves the multiple nullable ForeignKey pattern for spectrum ownership with the following enhancements:
Centralization & DRY:
Database Integrity:
Code Quality:
Documentation:
No breaking changes - full backward compatibility maintained.