From 7f0519afbeeb76d4f29a04d7a0a671930eba70b7 Mon Sep 17 00:00:00 2001 From: tomd Date: Mon, 12 Jan 2015 15:40:33 +0000 Subject: [PATCH] Fix sort changelist for objects with sortable fk Loading the test app '/admin/app/project/sort/' changelist failed with the following error: UnboundLocalError: local variable 'objects' referenced before assignment (utils.py, check_model_is_sortable) See test sample_app test_adminsortable_change_list_view_loads_with_sortable_fk --- adminsortable/utils.py | 2 +- sample_project/app/tests.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/adminsortable/utils.py b/adminsortable/utils.py index 3452351..51dd32b 100644 --- a/adminsortable/utils.py +++ b/adminsortable/utils.py @@ -30,5 +30,5 @@ def check_model_is_sortable(cls): objects = cls.model.objects else: objects = cls.objects - return get_is_sortable(objects.all()) + return get_is_sortable(objects.all()) return False diff --git a/sample_project/app/tests.py b/sample_project/app/tests.py index 9871a43..45f2361 100644 --- a/sample_project/app/tests.py +++ b/sample_project/app/tests.py @@ -12,7 +12,7 @@ from django.test.client import Client from adminsortable.models import Sortable from adminsortable.utils import get_is_sortable -from app.models import Category, Person +from app.models import Category, Person, Project class TestSortableModel(Sortable): @@ -176,3 +176,13 @@ class SortableTestCase(TestCase): self.assertEqual(self.first_person, result, 'Previous person should ' 'be "{0}"'.format(self.first_person)) + + def test_adminsortable_change_list_view_loads_with_sortable_fk(self): + category1 = self.create_category(title='Category 3') + Project.objects.create(category=category1, description="foo") + + self.client.login(username=self.user.username, + password=self.user_raw_password) + response = self.client.get('/admin/app/project/sort/') + self.assertEquals(response.status_code, httplib.OK, + 'Unable to reach sort view.')