Opened 9 years ago
Closed 9 years ago
#27356 closed Bug (fixed)
admin lookup_allowed incorrectly returns False for a nested reverse OneToOneField
| Reported by: | Tobias Krönke | Owned by: | |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | desecho@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Assume these 3 models in an app called foo:
class Somebody(models.Model): user = models.OneToOneField(AUTH_USER_MODEL) class Profile(models.Model): # we want an admin for this and filter on related data! who = models.OneToOneField(Somebody) class ClientInfo(models.Model): who = models.OneToOneField(Somebody) filter_by_me_please = models.CharField(db_index=True, max_length=20, blank=True)
and this profile admin:
class ProfileAdmin(admin.ModelAdmin): list_filter = ('who__clientinfo__filter_by_me_please', ) admin.site.register(Profile, ProfileAdmin)
I get this error
DisallowedModelAdminLookup at /admin/foo/profile/ Filtering by who__clientinfo__filter_by_me_please not allowed
on opening http://localhost:8000/admin/foo/profile/?who__clientinfo__filter_by_me_please=yay
The 3 lookup levels seem to be important to reproduce this.
Attachments (1)
Change History (13)
comment:1 by , 9 years ago
| Summary: | admin lookup_allowed returns False for a filter which is in list_filter → admin lookup_allowed incorrectly returns False for a nested reverse OneToOneField |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 9 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:6 by , 9 years ago
| Owner: | set to |
|---|---|
| Patch needs improvement: | set |
| Status: | new → assigned |
comment:7 by , 9 years ago
| Patch needs improvement: | unset |
|---|
comment:8 by , 9 years ago
| Patch needs improvement: | set |
|---|
comment:9 by , 9 years ago
| Has patch: | unset |
|---|---|
| Owner: | removed |
| Patch needs improvement: | unset |
| Status: | assigned → new |
I don't have idea how to fix this without breaking admin_views.tests.AdminViewBasicTest.test_disallowed_filtering.
comment:10 by , 9 years ago
| Cc: | added |
|---|---|
| Version: | 1.10 → master |
I added a project to easily reproduce the problem. Admin credentials - admin/iaN4viph8653 .
/admin/app/profile/?who__clientinfo__filter_by_me_please=test&who__department__code=123
by , 9 years ago
| Attachment: | djtest.zip added |
|---|
Reproduced at a4e9e834e3dfc8d5a024a78c765f193105d41a48.