1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #35020 -- Fixed ModelAdmin.lookup_allowed() for non-autofield primary keys.

Thanks Joshua Goodwin for the report.

Regression in 45ecd9acca.
This commit is contained in:
Sarah Boyce
2023-12-06 19:03:41 +01:00
committed by Mariusz Felisiak
parent 00ef74376e
commit f80669d2f5
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):