Features: 1) Update URL generation logic in admin autocomplete to use _meta for app and model names;
Fixes: 1) Ensure default value for `lookup_val` is an empty string if not provided; 2) Correct `field_name` parameter in the autocomplete URL to use `field_path`; Extra: 1) Minor cleanup by removing redundant variable declarations.
This commit is contained in:
parent
c5397c6608
commit
90c8f87502
1 changed files with 5 additions and 7 deletions
|
|
@ -49,15 +49,13 @@ class RelatedAutocompleteFilter(FieldListFilter):
|
|||
self.field_path = field_path
|
||||
|
||||
self.lookup_kwarg = f"{field_path}__{field.target_field.name}__exact"
|
||||
self.lookup_val = params.get(self.lookup_kwarg)
|
||||
self.lookup_val = params.get(self.lookup_kwarg, "")
|
||||
|
||||
rel_model = field.remote_field.model
|
||||
app_label = rel_model._meta.app_label
|
||||
model_name = rel_model._meta.model_name
|
||||
url_name = f"admin:{app_label}_{model_name}_autocomplete"
|
||||
opts = model_admin.model._meta
|
||||
url_name = f"admin:{opts.app_label}_{opts.model_name}_autocomplete"
|
||||
self.autocomplete_url = (
|
||||
reverse(url_name)
|
||||
+ f"?field_name={field.name}&limit={self.limit}"
|
||||
+ f"?field_name={field_path}&limit={self.limit}"
|
||||
)
|
||||
|
||||
def expected_parameters(self):
|
||||
|
|
@ -76,7 +74,7 @@ class RelatedAutocompleteFilter(FieldListFilter):
|
|||
"display": _("—"),
|
||||
"autocomplete_url": self.autocomplete_url,
|
||||
"lookup_kwarg": self.lookup_kwarg,
|
||||
"lookup_val": self.lookup_val or "",
|
||||
"lookup_val": self.lookup_val,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue