diff options
author | sarahboyce <sarahvboyce95@gmail.com> | 2023-03-18 10:18:11 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-28 09:26:39 +0200 |
commit | 45ecd9acca9b36093e274f47b6877a5f79108d9e (patch) | |
tree | 5b6b40aef6105d648476736f50464644f6c421cd /django | |
parent | d687febce5868545f99974d2499a91f81a32fef5 (diff) | |
download | django-45ecd9acca9b36093e274f47b6877a5f79108d9e.tar.gz |
Fixed #28384 -- Fixed ModelAdmin.lookup_allowed() for OneToOneField primary keys and nested relations.
Diffstat (limited to 'django')
-rw-r--r-- | django/contrib/admin/options.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 5240b07cd6..49c816dc9e 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -461,12 +461,14 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass): # Lookups on nonexistent fields are ok, since they're ignored # later. break - # It is allowed to filter on values that would be found from local - # model anyways. For example, if you filter on employee__department__id, - # then the id value would be found already from employee__department_id. if not prev_field or ( prev_field.is_relation - and field not in prev_field.path_infos[-1].target_fields + and field not in model._meta.parents.values() + and field is not model._meta.auto_field + and ( + model._meta.auto_field is None + or part not in getattr(prev_field, "to_fields", []) + ) ): relation_parts.append(part) if not getattr(field, "path_infos", None): |