(self, lookup, value, request)
| 494 | ) |
| 495 | |
| 496 | def lookup_allowed(self, lookup, value, request): |
| 497 | from django.contrib.admin.filters import SimpleListFilter |
| 498 | |
| 499 | model = self.model |
| 500 | # Check FKey lookups that are allowed, so that popups produced by |
| 501 | # ForeignKeyRawIdWidget, on the basis of ForeignKey.limit_choices_to, |
| 502 | # are allowed to work. |
| 503 | for fk_lookup in model._meta.related_fkey_lookups: |
| 504 | # As ``limit_choices_to`` can be a callable, invoke it here. |
| 505 | if callable(fk_lookup): |
| 506 | fk_lookup = fk_lookup() |
| 507 | if (lookup, value) in widgets.url_params_from_lookup_dict( |
| 508 | fk_lookup |
| 509 | ).items(): |
| 510 | return True |
| 511 | |
| 512 | relation_parts = [] |
| 513 | prev_field = None |
| 514 | parts = lookup.split(LOOKUP_SEP) |
| 515 | for part in parts: |
| 516 | try: |
| 517 | field = model._meta.get_field(part) |
| 518 | except FieldDoesNotExist: |
| 519 | # Lookups on nonexistent fields are ok, since they're ignored |
| 520 | # later. |
| 521 | break |
| 522 | if not prev_field or ( |
| 523 | prev_field.is_relation |
| 524 | and field not in model._meta.parents.values() |
| 525 | and field is not model._meta.auto_field |
| 526 | and ( |
| 527 | model._meta.auto_field is None |
| 528 | or part not in getattr(prev_field, "to_fields", []) |
| 529 | ) |
| 530 | and (field.is_relation or not field.primary_key) |
| 531 | ): |
| 532 | relation_parts.append(part) |
| 533 | if not getattr(field, "path_infos", None): |
| 534 | # This is not a relational field, so further parts |
| 535 | # must be transforms. |
| 536 | break |
| 537 | prev_field = field |
| 538 | model = field.path_infos[-1].to_opts.model |
| 539 | |
| 540 | if len(relation_parts) <= 1: |
| 541 | # Either a local field filter, or no fields at all. |
| 542 | return True |
| 543 | valid_lookups = {self.date_hierarchy} |
| 544 | for filter_item in self.get_list_filter(request): |
| 545 | if isinstance(filter_item, type) and issubclass( |
| 546 | filter_item, SimpleListFilter |
| 547 | ): |
| 548 | valid_lookups.add(filter_item.parameter_name) |
| 549 | elif isinstance(filter_item, (list, tuple)): |
| 550 | valid_lookups.add(filter_item[0]) |
| 551 | else: |
| 552 | valid_lookups.add(filter_item) |
| 553 |
no test coverage detected