Skip to content

Commit dd00a10

Browse files
committed
Clean up some cruft and add the print_tree method to the node model
1 parent 411ae51 commit dd00a10

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

nested_intervals/models.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,13 @@ def save(self, *args, **kwargs):
366366

367367
super(NestedIntervalsModel, self).save(*args, **kwargs)
368368

369-
save.alters_data = True
370-
371369
def delete(self, *args, **kwargs):
372370
"""Calling ``delete`` on a node will delete it as well as its full
373371
subtree, as opposed to reattaching all the subnodes to its parent node.
374372
375373
``delete`` will not return anything. """
376374
self.get_descendants(include_self=True).delete()
377375

378-
delete.alters_data = True
379-
380376
def _get_user_field_names(self):
381377
""" Returns the list of user defined (i.e. non-nested_intervals internal) field names. """
382378
field_names = []
@@ -385,3 +381,12 @@ def _get_user_field_names(self):
385381
if (field.name not in internal_fields) and (not isinstance(field, AutoField)) and (not field.primary_key):
386382
field_names.append(field.name)
387383
return field_names
384+
385+
def print_tree(self, indent=0):
386+
print("{indent}{name} ({left}, {right})".format(
387+
indent=" "*indent,
388+
name=getattr(node, "name", node.id),
389+
left=node.left,
390+
right=node.right))
391+
for child in node.get_children():
392+
self.print_tree(child, indent+1)

tests/mydatabase

-103 KB
Binary file not shown.

0 commit comments

Comments
 (0)