{{{#!python
class Country(models.Model):
id = models.CharField(max_length=2, primary_key=True)
class Place(models.Model):
country = models.ForeignKey(Country, models.CASCADE)
}}}
And a ModelAdmin with this list_filter:
{{{#!python
@admin.register(models.Place)
class PlaceAdmin(admin.ModelAdmin):
list_filter = ["country"]
}}}
Since 45ecd9acca9b36093e274f47b6877a5f79108d9e, filtering places by
country in the admin site raises
`django.contrib.admin.exceptions.DisallowedModelAdminLookup: Filtering by
country__id__exact not allowed`
--
Ticket URL: <https://code.djangoproject.com/ticket/35020>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Sarah Boyce (added)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
I can reproduce in latest Django main and I confirm that this is a
regression in the reported revision
45ecd9acca9b36093e274f47b6877a5f79108d9e
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:1>
* owner: nobody => Sarah Boyce
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:3>
* needs_better_patch: 0 => 1
* needs_docs: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:4>
* needs_better_patch: 1 => 0
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:5>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"f80669d2f5a5f1db9e9b73ca893fefba34f955e7" f80669d]:
{{{
#!CommitTicketReference repository=""
revision="f80669d2f5a5f1db9e9b73ca893fefba34f955e7"
Fixed #35020 -- Fixed ModelAdmin.lookup_allowed() for non-autofield
primary keys.
Thanks Joshua Goodwin for the report.
Regression in 45ecd9acca9b36093e274f47b6877a5f79108d9e.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:7>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"454fd50efb4b6bba54abdbcc01507190c780382f" 454fd50e]:
{{{
#!CommitTicketReference repository=""
revision="454fd50efb4b6bba54abdbcc01507190c780382f"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:8>
Comment (by aleksanb):
Hi.
This seems to have broken django admin url filtering on foreign keys as
well.
I have a model, PriceGroup with FK to Booking, and when i attempt to
filter PriceGroup in django admin on ?booking_id=... in the url i get
`Error: Filtering by booking not allowed` in a small red alert box.
The foreign key being declared as
booking = models.ForeignKey(Booking, null=False,
on_delete=models.PROTECT)
and booking having the default primary key that django makes.
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:9>
Comment (by Sarah Boyce):
Hi @aleksanb 👋
Yes, this has been raised here:
https://code.djangoproject.com/ticket/35087
--
Ticket URL: <https://code.djangoproject.com/ticket/35020#comment:10>