Opened 9 years ago

Closed 8 years ago

#25606 closed Bug (fixed)

Add support for "__" lookup in RelatedOnlyFieldListFilter

Reported by: Ivo van Doesburg Owned by: nobody
Component: contrib.admin Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Given this ModelAdmin:

class BookAdminRelatedOnlyFilter(admin.ModelAdmin):
    list_filter = (
        'edition__publisher',
        ('edition__publisher', RelatedOnlyFieldListFilter),
    )

The first filter works fine, but the second results in a FieldError: Cannot resolve keyword 'publisher' into field.

The reason this happens is because RelatedOnlyFieldListFilter uses field.name instead of the field_path, where field is the result of get_fields_from_path, which returns the 'publisher' field

This patch fixes this behaviour: https://github.com/django/django/compare/master...quarkness:related-only-filter-field-path
It also improves performance by using .distinct() on the database to get unique values instead of set()

Change History (7)

comment:1 by Tim Graham, 9 years ago

Needs tests: set
Summary: field_paths do not work in list_filter when using RelatedOnlyFieldListFilterAdd support for "__" lookup in RelatedOnlyFieldListFilter
Triage Stage: UnreviewedAccepted

The PR from duplicate ticket #25608 also lacks tests.

comment:2 by Tim Graham, 9 years ago

Needs tests: unset
Patch needs improvement: set

comment:3 by Andrey Kuzmin, 8 years ago

Patch needs improvement: unset

comment:4 by Tim Graham, 8 years ago

Patch needs improvement: set

Left some more comments and tests aren't passing.

comment:5 by Andrey Kuzmin, 8 years ago

Patch needs improvement: unset

comment:6 by Nick Sandford, 8 years ago

Triage Stage: AcceptedReady for checkin

Looks good.

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

Resolution: fixed
Status: newclosed

In 815f4d2:

Fixed #25606 -- Added support for "" lookup in RelatedOnlyFieldList

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