My favorites
▼
|
Sign in
django-mptt
Utilities for implementing Modified Preorder Tree Traversal
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
57
attachment: mpttpatch.txt
(1.9 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
### Eclipse Workspace Patch 1.0
#P mptt
Index: mptt/models.py
===================================================================
--- mptt/models.py (revision 121)
+++ mptt/models.py (working copy)
@@ -68,22 +68,22 @@
return (getattr(self, self._meta.right_attr) -
getattr(self, self._meta.left_attr) - 1) / 2
-def get_next_sibling(self):
+def get_next_sibling(self, **filters):
"""
Returns this model instance's next sibling in the tree, or
``None`` if it doesn't have a next sibling.
"""
opts = self._meta
if self.is_root_node():
- filters = {
+ filters.update({
'%s__isnull' % opts.parent_attr: True,
'%s__gt' % opts.tree_id_attr: getattr(self, opts.tree_id_attr),
- }
+ })
else:
- filters = {
+ filters.update({
opts.parent_attr: getattr(self, '%s_id' % opts.parent_attr),
'%s__gt' % opts.left_attr: getattr(self, opts.right_attr),
- }
+ })
sibling = None
try:
@@ -92,23 +92,23 @@
pass
return sibling
-def get_previous_sibling(self):
+def get_previous_sibling(self, **filters):
"""
Returns this model instance's previous sibling in the tree, or
``None`` if it doesn't have a previous sibling.
"""
opts = self._meta
if self.is_root_node():
- filters = {
+ filters.update({
'%s__isnull' % opts.parent_attr: True,
'%s__lt' % opts.tree_id_attr: getattr(self, opts.tree_id_attr),
- }
+ })
order_by = '-%s' % opts.tree_id_attr
else:
- filters = {
+ filters.update({
opts.parent_attr: getattr(self, '%s_id' % opts.parent_attr),
'%s__lt' % opts.right_attr: getattr(self, opts.left_attr),
- }
+ })
order_by = '-%s' % opts.right_attr
sibling = None
Powered by
Google Project Hosting