mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #27356 -- Fixed ModelAdmin.lookup_allowed() for some nested relations.
This commit is contained in:
committed by
Tim Graham
parent
27793431cf
commit
b27166b769
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user