-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Django-MPTT instead of home brewed tree functions #183
base: develop
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That worries me. Is there absolutely no way of reversing this migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the get_children()
method of MPTTModel not work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would. I might need to include the filter on it though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.