My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 23 attachment: complex-deletion.patch (2.5 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Index: parts/extras/django-mptt/mptt/tests/tests.py
===================================================================
--- parts/extras/django-mptt/mptt/tests/tests.py (revision 105)
+++ parts/extras/django-mptt/mptt/tests/tests.py (working copy)
@@ -1,6 +1,7 @@
r"""
>>> from datetime import date
>>> from mptt.exceptions import InvalidMove
+>>> from mptt.tests.models import Book
>>> from mptt.tests.models import Category, Genre, Insert, MultiOrder, Node, OrderedInsertion, Tree

>>> def print_tree_details(nodes):
@@ -416,6 +417,34 @@
4 - 4 0 1 4
8 4 4 1 2 3

+# Delete a node with children from a more comlex tree
+>>> fiction = Book.objects.create(name='Fiction')
+>>> scifi = Book.objects.create(name='Science Fiction', parent=fiction)
+>>> fantasy = Book.objects.create(name='Fantasy', parent=fiction)
+>>> thriller = Book.objects.create(name='Thriller', parent=fiction)
+>>> horror = Book.objects.create(name='Horror', parent=scifi)
+>>> commedy = Book.objects.create(name='Commedy', parent=scifi)
+>>> bad = Book.objects.create(name='Bad', parent=horror)
+>>> elves = Book.objects.create(name='Elves', parent=fantasy)
+>>> print_tree_details(Book.tree.all())
+1 - 1 0 1 16
+2 1 1 1 2 9
+5 2 1 2 3 6
+7 5 1 3 4 5
+6 2 1 2 7 8
+3 1 1 1 10 13
+8 3 1 2 11 12
+4 1 1 1 14 15
+
+>>> scifi = Book.objects.get(pk=scifi.pk)
+>>> scifi.delete()
+>>> print_tree_details(Book.tree.all())
+1 - 1 0 1 8
+3 1 1 1 2 5
+8 3 1 2 3 4
+4 1 1 1 6 7
+
+
# Moving Nodes Manually #######################################################
>>> games = Category.objects.create(name='PC & Video Games')
>>> wii = Category.objects.create(name='Nintendo Wii', parent=games)
Index: parts/extras/django-mptt/mptt/tests/models.py
===================================================================
--- parts/extras/django-mptt/mptt/tests/models.py (revision 105)
+++ parts/extras/django-mptt/mptt/tests/models.py (working copy)
@@ -16,6 +16,14 @@
def __unicode__(self):
return self.name

+class Book(models.Model):
+ name = models.CharField(max_length=50, unique=True)
+ parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
+
+ def __unicode__(self):
+ return self.name
+
+
class Insert(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')

@@ -43,6 +51,7 @@

mptt.register(Category)
mptt.register(Genre)
+mptt.register(Book)
mptt.register(Insert)
mptt.register(MultiOrder, order_insertion_by=['name', 'size', 'date'])
mptt.register(Node, left_attr='does', right_attr='zis', level_attr='madness',
Powered by Google Project Hosting