django-polymorphic / django-polymorphic-tree

Polymorphic MPTT tree support for models
Other
170 stars 45 forks source link

Allow child type validation in memory #63

Closed dannyshaw closed 6 years ago

dannyshaw commented 6 years ago

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_types set, 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 the polymorphic_ctype_id is 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.

codecov[bot] commented 6 years ago

Codecov Report

Merging #63 into master will increase coverage by 1%. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #63   +/-   ##
=======================================
+ Coverage   63.84%   64.85%   +1%     
=======================================
  Files          12       12           
  Lines         780      791   +11     
=======================================
+ Hits          498      513   +15     
+ Misses        282      278    -4
Impacted Files Coverage Δ
polymorphic_tree/tests/test_models.py 100% <100%> (ø) :arrow_up:
polymorphic_tree/models.py 63.79% <100%> (+3.79%) :arrow_up:
polymorphic_tree/tests/models.py 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6aaff56...b06fa21. Read the comment docs.

vdboor commented 6 years ago

That is a great improvement, thanks!