diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2023-12-06 19:03:41 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-12-07 06:16:35 +0100 |
| commit | f80669d2f5a5f1db9e9b73ca893fefba34f955e7 (patch) | |
| tree | 24b070a845073a362377dfa06c8ec4ee9febe2aa /django/contrib/admin/options.py | |
| parent | 00ef74376e382cf33d6a9529bb9fc1b412e0bc7d (diff) | |
Fixed #35020 -- Fixed ModelAdmin.lookup_allowed() for non-autofield primary keys.
Thanks Joshua Goodwin for the report.
Regression in 45ecd9acca9b36093e274f47b6877a5f79108d9e.
Diffstat (limited to 'django/contrib/admin/options.py')
| -rw-r--r-- | django/contrib/admin/options.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index b045b2df02..af69f4cb3b 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -474,24 +474,24 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass): # Lookups on nonexistent fields are ok, since they're ignored # later. break - if not prev_field or ( - prev_field.is_relation - 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): # This is not a relational field, so further parts # must be transforms. break + if ( + not prev_field + or (field.is_relation and field not in model._meta.parents.values()) + or ( + prev_field.is_relation + and model._meta.auto_field is None + and part not in getattr(prev_field, "to_fields", []) + ) + ): + relation_parts.append(part) prev_field = field model = field.path_infos[-1].to_opts.model - if len(relation_parts) <= 1: + if not relation_parts: # Either a local field filter, or no fields at all. return True valid_lookups = {self.date_hierarchy} |
