Opened 10 years ago

Closed 10 years ago

#27356 closed Bug (fixed)

admin lookup_allowed incorrectly returns False for a nested reverse OneToOneField

Reported by: Tobias Krönke Owned by: Tim Graham <timograham@…>
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)

djtest.zip​ (18.1 KB ) - added by Anton Samarchyan 10 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Tim Graham, 10 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 Mariusz Felisiak, 10 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: new → assigned

comment:3 by Mariusz Felisiak, 10 years ago

Has patch: set

comment:4 by Tobias McNulty, 10 years ago

Owner: changed from Mariusz Felisiak to Tobias McNulty

Reviewing at DUTH sprint.

comment:5 by Tobias McNulty, 10 years ago

Owner: Tobias McNulty removed
Status: assigned → new

comment:6 by Mariusz Felisiak, 10 years ago

Owner: set to Mariusz Felisiak
Patch needs improvement: set
Status: new → assigned

comment:7 by Mariusz Felisiak, 10 years ago

Patch needs improvement: unset

comment:8 by Tim Graham, 10 years ago

Patch needs improvement: set

comment:9 by Mariusz Felisiak, 10 years ago

Has patch: unset
Owner: Mariusz Felisiak 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 Anton Samarchyan, 10 years ago

Cc: desecho@… added
Version: 1.10 → master

I added a project to easily reproduce the problem. Admin credentials - admin/iaN4viph8653 .
/admin/app/profile/?whoclientinfofilter_by_me_please=test&whodepartmentcode=123

Version 2, edited 10 years ago by Anton Samarchyan (previous) (next) (diff)

by Anton Samarchyan, 10 years ago

Attachment: djtest.zip​ added

comment:11 by Anton Samarchyan, 10 years ago

Has patch: set

I added a ​PR

comment:12 by Tim Graham <timograham@…>, 10 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: → fixed
Status: new → closed

In b27166b:

Fixed #27356 -- Fixed ModelAdmin.lookup_allowed() for some nested relations.

Note: See TracTickets for help on using tickets.
Back to Top