Allow child type validation in memory #63
Merged
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 PR introduces the ability to validate a child type against the parent prior to the child being saved in the database.
With restricted
child_typesset, django admin would not allow you to add a valid child type because it tries to validate the object before creating it in the db and thepolymorphic_ctype_idis not set to be able to answer the question.This change simply calls the available
pre_save_polymorphic()method to set the id in memory prior to the check.Test added to expose issue.