Opened 9 years ago
Closed 9 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 , 9 years ago
Needs tests: | set |
---|---|
Summary: | field_paths do not work in list_filter when using RelatedOnlyFieldListFilter → Add support for "__" lookup in RelatedOnlyFieldListFilter |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 9 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | set |
comment:3 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:4 by , 9 years ago
Patch needs improvement: | set |
---|
Left some more comments and tests aren't passing.
comment:5 by , 9 years ago
Patch needs improvement: | unset |
---|
The PR from duplicate ticket #25608 also lacks tests.