Use Django-MPTT instead of home brewed tree functions#183
Use Django-MPTT instead of home brewed tree functions#183AidanCurrah wants to merge 1 commit intodevelopfrom
Conversation
| set_page_child_levels(homepage, 0) | ||
|
|
||
| def reverse_page_tree_level(apps, schema_editor): | ||
| # We don't have anything here are we're removing the 'level' field anyway |
There was a problem hiding this comment.
That worries me. Is there absolutely no way of reversing this migration?
There was a problem hiding this comment.
We shouldn't have to have anything. The forwards migration just populates the new 'level' field that gets added with this migration.
When going backwards we don't need to do anything since the field is getting removed anyway.
| @cached_property | ||
| def children(self): | ||
| '''The child pages for this page.''' | ||
| children = [] | ||
| if self.right - self.left > 1: # Optimization - don't fetch children | ||
| # we know aren't there! | ||
| for child in self.child_set.filter(is_content_object=False): | ||
| child.parent = self | ||
| children.append(child) | ||
| return children |
There was a problem hiding this comment.
Would the get_children() method of MPTTModel not work here?
There was a problem hiding this comment.
It would. I might need to include the filter on it though
There was a problem hiding this comment.
However using get_children() avoids the slight optimisation of having children.parent being the current instance and avoiding a DB lookup
This migrates the CMS to use Django MPTT and it's helper classes/functions for our tree structure and allows us to get rid of some overly complex functions.