Skip to content

Loading…

bug when using a custom PK name #164

Merged
merged 4 commits into from

2 participants

@slafs

my fixes for getting a next sibling on non-root nodes when model has a custom primary key name

@craigds craigds merged commit 45684c2 into django-mptt:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 31 additions and 2 deletions.
  1. +10 −0 tests/myapp/models.py
  2. +20 −1 tests/myapp/tests.py
  3. +1 −1 tests/runtests.sh
View
10 tests/myapp/models.py
@@ -86,3 +86,13 @@ def __unicode__(self):
class Student(Person):
type = models.CharField(max_length=50)
+
+class CustomPKName(MPTTModel):
+ my_id = models.AutoField(db_column='my_custom_name', primary_key=True)
+ name = models.CharField(max_length=50)
+ parent = models.ForeignKey('self', null=True, blank=True,
+ related_name='children', db_column="my_cusom_parent")
+
+ def __unicode__(self):
+ return self.name
+
View
21 tests/myapp/tests.py
@@ -3,7 +3,7 @@
from django.test import TestCase
from mptt.exceptions import InvalidMove
-from myapp.models import Category, Genre
+from myapp.models import Category, Genre, CustomPKName
def get_tree_details(nodes):
@@ -346,3 +346,22 @@ class InterTreeMovementTestCase(TestCase):
class PositionedInsertionTestCase(TestCase):
pass
+
+class CustomPKNameTestCase(TestCase):
+ def setUp(self):
+ c1 = CustomPKName.objects.create(name="c1")
+ c11 = CustomPKName.objects.create(name="c11", parent=c1)
+ c12 = CustomPKName.objects.create(name="c12", parent=c1)
+
+ c2 = CustomPKName.objects.create(name="c2")
+ c21 = CustomPKName.objects.create(name="c21", parent=c2)
+ c22 = CustomPKName.objects.create(name="c22", parent=c2)
+
+ c3 = CustomPKName.objects.create(name="c3")
+
+ def test_get_next_sibling(self):
+ root = CustomPKName.objects.get(name="c12")
+ sib = root.get_next_sibling()
+ self.assertTrue(sib is None)
+
+
View
2 tests/runtests.sh
@@ -2,4 +2,4 @@
export PYTHONPATH="./"
export DJANGO_SETTINGS_MODULE='settings'
-django-admin test --pythonpath="../"
+django-admin.py test --pythonpath="../"
Something went wrong with that request. Please try again.