summaryrefslogtreecommitdiff
path: root/tests/modeladmin/tests.py
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2023-12-06 19:03:41 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-07 08:44:59 +0100
commit454fd50efb4b6bba54abdbcc01507190c780382f (patch)
treeaf2cc9907c2303602e638453cc01f4972b3fd946 /tests/modeladmin/tests.py
parentda2475a21719976815f87408ee404f0e8512fc31 (diff)
[5.0.x] Fixed #35020 -- Fixed ModelAdmin.lookup_allowed() for non-autofield primary keys.
Thanks Joshua Goodwin for the report. Regression in 45ecd9acca9b36093e274f47b6877a5f79108d9e. Backport of f80669d2f5a5f1db9e9b73ca893fefba34f955e7 from main
Diffstat (limited to 'tests/modeladmin/tests.py')
-rw-r--r--tests/modeladmin/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index f2763ecc0f..1a9dbdb7cb 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -163,6 +163,20 @@ class ModelAdminTests(TestCase):
)
@isolate_apps("modeladmin")
+ def test_lookup_allowed_non_autofield_primary_key(self):
+ class Country(models.Model):
+ id = models.CharField(max_length=2, primary_key=True)
+
+ class Place(models.Model):
+ country = models.ForeignKey(Country, models.CASCADE)
+
+ class PlaceAdmin(ModelAdmin):
+ list_filter = ["country"]
+
+ ma = PlaceAdmin(Place, self.site)
+ self.assertIs(ma.lookup_allowed("country__id__exact", "DE", request), True)
+
+ @isolate_apps("modeladmin")
def test_lookup_allowed_foreign_primary(self):
class Country(models.Model):
name = models.CharField(max_length=256)