summaryrefslogtreecommitdiff
path: root/tests/modeladmin
diff options
context:
space:
mode:
authorAnton Samarchyan <anton.samarchyan@savoirfairelinux.com>2017-01-16 15:06:48 -0500
committerTim Graham <timograham@gmail.com>2017-02-07 19:33:26 -0500
commitb27166b7690fbe5d695b828361a74699ddd2678a (patch)
tree527dd0c1f0343a3364bb6ae73c38dee9d4729b13 /tests/modeladmin
parent27793431cf21a82809c0c39a7c0188a2d83bf475 (diff)
Fixed #27356 -- Fixed ModelAdmin.lookup_allowed() for some nested relations.
Diffstat (limited to 'tests/modeladmin')
-rw-r--r--tests/modeladmin/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index b85764a290..4862664dbc 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -8,8 +8,10 @@ from django.contrib.admin.options import (
from django.contrib.admin.sites import AdminSite
from django.contrib.admin.widgets import AdminDateWidget, AdminRadioSelect
from django.contrib.auth.models import User
+from django.db import models
from django.forms.widgets import Select
from django.test import SimpleTestCase, TestCase
+from django.test.utils import isolate_apps
from .models import Band, Concert
@@ -90,6 +92,33 @@ class ModelAdminTests(TestCase):
ma = BandAdmin(Band, self.site)
self.assertTrue(ma.lookup_allowed('name__nonexistent', 'test_value'))
+ @isolate_apps('modeladmin')
+ def test_lookup_allowed_onetoone(self):
+ class Department(models.Model):
+ code = models.CharField(max_length=4, unique=True)
+
+ class Employee(models.Model):
+ department = models.ForeignKey(Department, models.CASCADE, to_field="code")
+
+ class EmployeeProfile(models.Model):
+ employee = models.OneToOneField(Employee, models.CASCADE)
+
+ class EmployeeInfo(models.Model):
+ employee = models.OneToOneField(Employee, models.CASCADE)
+ description = models.CharField(max_length=100)
+
+ class EmployeeProfileAdmin(ModelAdmin):
+ list_filter = [
+ 'employee__employeeinfo__description',
+ 'employee__department__code',
+ ]
+
+ ma = EmployeeProfileAdmin(EmployeeProfile, self.site)
+ # Reverse OneToOneField
+ self.assertIs(ma.lookup_allowed('employee__employeeinfo__description', 'test_value'), True)
+ # OneToOneField and ForeignKey
+ self.assertIs(ma.lookup_allowed('employee__department__code', 'test_value'), True)
+
def test_field_arguments(self):
# If fields is specified, fieldsets_add and fieldsets_change should
# just stick the fields into a formsets structure and return it.