Opened 8 years ago

Closed 8 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 8 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Tim Graham, 8 years ago

Summary: admin lookup_allowed returns False for a filter which is in list_filteradmin lookup_allowed incorrectly returns False for a nested reverse OneToOneField
Triage Stage: UnreviewedAccepted

comment:2 by Mariusz Felisiak, 8 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 by Mariusz Felisiak, 8 years ago

Has patch: set

comment:4 by Tobias McNulty, 8 years ago

Owner: changed from Mariusz Felisiak to Tobias McNulty

Reviewing at DUTH sprint.

comment:5 by Tobias McNulty, 8 years ago

Owner: Tobias McNulty removed
Status: assignednew

comment:6 by Mariusz Felisiak, 8 years ago

Owner: set to Mariusz Felisiak
Patch needs improvement: set
Status: newassigned

comment:7 by Mariusz Felisiak, 8 years ago

Patch needs improvement: unset

comment:8 by Tim Graham, 8 years ago

Patch needs improvement: set

comment:9 by Mariusz Felisiak, 8 years ago

Has patch: unset
Owner: Mariusz Felisiak removed
Patch needs improvement: unset
Status: assignednew

I don't have idea how to fix this without breaking admin_views.tests.AdminViewBasicTest.test_disallowed_filtering.

comment:10 by Anton Samarchyan, 8 years ago

Cc: desecho@… added
Version: 1.10master

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

Last edited 8 years ago by Anton Samarchyan (previous) (diff)

by Anton Samarchyan, 8 years ago

Attachment: djtest.zip added

comment:11 by Anton Samarchyan, 8 years ago

Has patch: set

I added a PR

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

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In b27166b:

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

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