class Country(models.Model):
name = models.CharField(max_length=256)
class Place(models.Model):
country = models.ForeignKey(Country, models.CASCADE)
class Restaurant(models.Model):
place = models.OneToOneField(Place, models.CASCADE,
primary_key=True)
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant, models.CASCADE)
class WaiterAdmin(ModelAdmin):
list_filter = [
'restaurant__place__country',
]
ma = WaiterAdmin(Waiter, self.site)
self.assertIs(ma.lookup_allowed('restaurant__place__country',
'test_value'), True)
}}}
I think this is caused by the admin thinking that having a foreign key
field as a primary key is the same as concrete inheritance. So when you
try and check lookups for {{{restaurant__place__country}}} it thinks
'place' is the concrete parent of 'restaurant' and shortcuts it to
{{{restaurant__country}}} which isn't in 'list_filter'. And you can't add
{{{restaurant__country}}} to list_filter because country isn't actually on
restaurant.
--
Ticket URL: <https://code.djangoproject.com/ticket/28384>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Old description:
New description:
Wrote a failing test for `tests/modeladmin/tests.py` to demonstrate - same
--
Comment:
Bisected to 8f30556329b64005d63b66859a74752a0b261315.
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:1>
* status: new => assigned
* owner: nobody => Windson yang
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:2>
* cc: Sarah Boyce (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:2>
* owner: nobody => Sarah Boyce
* status: new => assigned
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/16661
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:4>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:7>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:8>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:9>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:10>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"45ecd9acca9b36093e274f47b6877a5f79108d9e" 45ecd9ac]:
{{{
#!CommitTicketReference repository=""
revision="45ecd9acca9b36093e274f47b6877a5f79108d9e"
Fixed #28384 -- Fixed ModelAdmin.lookup_allowed() for OneToOneField
primary keys and nested relations.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28384#comment:11>