Conversation
53e1602 to
9542b55
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #684 +/- ##
==========================================
+ Coverage 76.44% 76.75% +0.30%
==========================================
Files 22 22
Lines 1350 1368 +18
Branches 211 214 +3
==========================================
+ Hits 1032 1050 +18
Misses 250 250
Partials 68 68 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9542b55 to
f6c14ff
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a create_from_super method to the PolymorphicManager class that enables "recasting" an existing polymorphic model instance to a more specific subclass type. The method takes an instance of a parent class and creates a child class instance with the same database ID and inherited data, effectively converting the object down the inheritance hierarchy.
Key Changes:
- Adds
create_from_super()method toPolymorphicManagerfor model recasting functionality - Implements validation to ensure objects can only be cast to direct child classes
- Creates new test suite to verify recasting behavior across multiple inheritance levels
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| src/polymorphic/managers.py | Adds create_from_super manager method with validation, database operations, and content type updates to enable polymorphic recasting |
| src/polymorphic/tests/test_recasting.py | Adds test suite covering successful recasting from Model2C→Model2D and error cases for non-adjacent inheritance levels |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fa2d026 to
97c663f
Compare
|
It might be best to solve this upstream in Django - a solution to this would also work for polymorphic models because they are just multi-table models with a fancy manager. |
637a7d5 to
4e9272a
Compare
fe96c5f to
bdff41b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Joshua <jcoxwell@gmail.com> Co-authored-by: Brian Kohan <bckohan@gmail.com>
bdff41b to
6cd80a3
Compare
This PR replaces #65
It needs some more work. I would like it to support casting across multiple levels of hierarchy.
The discussion in #65 and the details of this long standing Django ticket should be considered.
Fixes #296