1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

[5.0.x] Fixed #35020 -- Fixed ModelAdmin.lookup_allowed() for non-autofield primary keys.

Thanks Joshua Goodwin for the report.

Regression in 45ecd9acca.

Backport of f80669d2f5 from main
This commit is contained in:
Sarah Boyce
2023-12-06 19:03:41 +01:00
committed by Mariusz Felisiak
parent da2475a217
commit 454fd50efb
3 changed files with 28 additions and 12 deletions

View File

@@ -162,6 +162,20 @@ class ModelAdminTests(TestCase):
True,
)
@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):