Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

AidanCurrah
Copy link
Contributor

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.

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +176 to +185
@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
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants