demiroren-teknoloji / django-admin-autocomplete-list-filter Goto Github PK
View Code? Open in Web Editor NEWAjax autocomplete list filter for Django admin
License: MIT License
Ajax autocomplete list filter for Django admin
License: MIT License
I'm using django 3, with the changes proposed in #6, and whenever multiple filters with autocomplete are present, only the last one seems to be working correctly.
The others do not react at all and the select menus are empty.
django admin raises exception 'staticfiles' is not a registered tag library
, because the staticfiles and admin_static template tag libraries are removed in 3.0.
There is a PR #3
that is not accepted
Currently this list filter fails to account for fields that span across foreignkey relationships, it will correctly parse the field as a ForeignKey but will attempt to find it on the Model that belongs to the current ModelAdmin, instead of traversing across models.
I can add a more concrete example if necessary.
I was investigating an admin list page slowness and found out that all options are queried and loaded into memory, which, in case of a large number of options (usually the motivation itself for using autocomplate) makes the page load very slowly.
Stack trace leading to the problem looks like this:
django/contrib/admin/options.py in wrapper(686)
return self.admin_site.admin_view(view)(*args, **kwargs)
django/views/decorators/cache.py in _wrapped_view_func(62)
response = view_func(request, *args, **kwargs)
django/contrib/admin/sites.py in inner(242)
return view(request, *args, **kwargs)
django/contrib/admin/options.py in changelist_view(1931)
cl = self.get_changelist_instance(request)
django/contrib/admin/options.py in get_changelist_instance(834)
return ChangeList(
django/contrib/admin/views/main.py in __init__(122)
self.queryset = self.get_queryset(request)
django/contrib/admin/views/main.py in get_queryset(503)
) = self.get_filters(request)
django/contrib/admin/views/main.py in get_filters(182)
spec = field_list_filter_class(
djaa_list_filter/admin.py in __init__(53)
super().__init__(field, request, params, model, model_admin, field_path)
django/contrib/admin/filters.py in __init__(188)
self.lookup_choices = self.field_choices(field, request, model_admin)
django/contrib/admin/filters.py in field_choices(225)
return field.get_choices(include_blank=False, ordering=ordering)
Using Django 4.1.1.
Hi,
I wanted to report that after this commit on django main repository the autocomplete list filter widget no longer works.
On first analysis, when instantiating the AjaxAutocompleteSelectWidget
object, its __init__
function calls super().__init__
passing a "rel" keyword argument which is no longer accepted by django AutocompleteMixin
init function, raising the following exception:
TypeError: __init__() got an unexpected keyword argument 'rel'
The offending change is in django/contrib/admin/widgets.py
file at line 385.
I haven't delved into it yet, but judging from the commit message, it seems that fix #29138 ("Allowed autocomplete fields to target a custom to_field rather than the PK") is directly related to the choice of replacing the "rel" kwarg with the "field" kwarg, breaking the interface.
Version: django-admin-autocomplete-list-filter = "1.0.1"
Stacktrace
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File ".venv/lib/python3.8/site-packages/djaa_list_filter/admin.py", line 13, in <module>
from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (.venv/lib/python3.8/site-packages/django/utils/translation/__init__.py)
django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(), ungettext(), and ungettext_lazy() are removed in Django 4.0
https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.