django-listview-search-admin-autocomplete 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. django_listview_search_admin_autocomplete-0.3.0/.gitignore +59 -0
  2. django_listview_search_admin_autocomplete-0.3.0/PKG-INFO +171 -0
  3. django_listview_search_admin_autocomplete-0.3.0/README.rst +134 -0
  4. django_listview_search_admin_autocomplete-0.3.0/pyproject.toml +74 -0
  5. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/__init__.py +0 -0
  6. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/admin.py +91 -0
  7. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/apps.py +5 -0
  8. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/migrations/__init__.py +0 -0
  9. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/models.py +3 -0
  10. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/easy-autocomplete.css +388 -0
  11. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/easy-autocomplete.min.css +11 -0
  12. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/easy-autocomplete.themes.css +248 -0
  13. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/easy-autocomplete.themes.min.css +11 -0
  14. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/jquery.easy-autocomplete.js +1649 -0
  15. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/jquery.easy-autocomplete.min.js +10 -0
  16. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/main.js +26 -0
  17. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/maps/easy-autocomplete.css.map +16 -0
  18. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/maps/easy-autocomplete.min.css.map +16 -0
  19. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/maps/easy-autocomplete.themes.css.map +16 -0
  20. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/easy_autocomplete/maps/easy-autocomplete.themes.min.css.map +16 -0
  21. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/static/search_admin_autocomplete/css/styles.css +12 -0
  22. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/templates/search_admin_autocomplete/change_list.html +13 -0
  23. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/tests.py +206 -0
  24. django_listview_search_admin_autocomplete-0.3.0/search_admin_autocomplete/views.py +3 -0
@@ -0,0 +1,59 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ *.egg-info/
18
+ *.egg
19
+ sdist/
20
+
21
+ # Virtual environments
22
+ venv/
23
+ ENV/
24
+ .env
25
+ .venv/
26
+
27
+ # Distribution / packaging (uv)
28
+ .uv/
29
+
30
+ # IDE
31
+ .idea/
32
+ *.iml
33
+ .vscode/
34
+ *.swp
35
+ *.swo
36
+ *~
37
+
38
+ # Testing
39
+ .pytest_cache/
40
+ .coverage
41
+ htmlcov/
42
+ .tox/
43
+ coverage.xml
44
+
45
+ # Django
46
+ *.log
47
+ local_settings.py
48
+ db.sqlite3
49
+ example/db.sqlite3
50
+
51
+ # OS
52
+ .DS_Store
53
+ Thumbs.db
54
+
55
+ # mypy
56
+ .mypy_cache/
57
+
58
+ # ruff
59
+ .ruff_cache/
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-listview-search-admin-autocomplete
3
+ Version: 0.3.0
4
+ Summary: Django admin autocomplete with related field support
5
+ Project-URL: Homepage, https://github.com/linevich/django-search-admin-autocomplete
6
+ Project-URL: Repository, https://github.com/linevich/django-search-admin-autocomplete
7
+ Project-URL: Documentation, https://github.com/linevich/django-search-admin-autocomplete#readme
8
+ Project-URL: Issues, https://github.com/linevich/django-search-admin-autocomplete/issues
9
+ Project-URL: Changelog, https://github.com/linevich/django-search-admin-autocomplete/releases
10
+ Author-email: linevich <mail@linevich.net>
11
+ Maintainer-email: Your Name <your@email.com>
12
+ License-Expression: MIT
13
+ Keywords: admin,autocomplete,django,search
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Environment :: Web Environment
16
+ Classifier: Framework :: Django
17
+ Classifier: Framework :: Django :: 3.2
18
+ Classifier: Framework :: Django :: 4.2
19
+ Classifier: Framework :: Django :: 5.0
20
+ Classifier: Framework :: Django :: 5.1
21
+ Classifier: Intended Audience :: Developers
22
+ Classifier: License :: OSI Approved :: MIT License
23
+ Classifier: Operating System :: OS Independent
24
+ Classifier: Programming Language :: Python
25
+ Classifier: Programming Language :: Python :: 3
26
+ Classifier: Programming Language :: Python :: 3.8
27
+ Classifier: Programming Language :: Python :: 3.9
28
+ Classifier: Programming Language :: Python :: 3.10
29
+ Classifier: Programming Language :: Python :: 3.11
30
+ Classifier: Programming Language :: Python :: 3.12
31
+ Classifier: Programming Language :: Python :: 3.13
32
+ Classifier: Topic :: Internet :: WWW/HTTP
33
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
34
+ Requires-Python: >=3.8
35
+ Requires-Dist: django>=3.2
36
+ Description-Content-Type: text/x-rst
37
+
38
+ Django-search-admin-autocomplete
39
+ ================================
40
+
41
+ .. image:: https://raw.githubusercontent.com/linevych/django-search-admin-autocomplete/master/doc/demo.gif
42
+
43
+ **This is a fork of** `django-search-admin-autocomplete <https://github.com/linevich/django-search-admin-autocomplete>`_ **(archived).** The original package is no longer maintained. This fork adds new features, modern Django support, and bug fixes.
44
+
45
+ Simple Django app that adds autocomplete search to the admin panel changelist view.
46
+
47
+ What's New
48
+ ----------
49
+
50
+ - **Related field search**: Search across ForeignKey relations (e.g., ``client__name``, ``category__title``)
51
+ - **Django 4+ / 5+ support**: Fixed deprecated ``url()`` imports
52
+ - **Modern build system**: ``pyproject.toml`` with hatchling (no more ``setup.py``)
53
+ - **Python 3.8–3.13** support
54
+ - **Comprehensive test suite** (18 tests)
55
+
56
+ Requirements
57
+ ============
58
+
59
+ - Python: 3.8+
60
+ - Django: 3.2+
61
+
62
+ Installation
63
+ ============
64
+
65
+ .. code-block:: bash
66
+
67
+ pip install django-listview-search-admin-autocomplete
68
+
69
+ .. code-block:: python
70
+
71
+ INSTALLED_APPS = [
72
+ ...
73
+ 'search_admin_autocomplete',
74
+ ...
75
+ ]
76
+
77
+ Usage
78
+ =====
79
+
80
+ Basic usage with direct fields:
81
+
82
+ .. code-block:: python
83
+
84
+ from search_admin_autocomplete.admin import SearchAutoCompleteAdmin
85
+
86
+ class MyModelAdmin(SearchAutoCompleteAdmin):
87
+ search_fields = ['name', 'description']
88
+
89
+ admin.site.register(MyModel, MyModelAdmin)
90
+
91
+ Related Field Support
92
+ =====================
93
+
94
+ Search across ForeignKey and related model fields using Django's ``__`` lookup syntax:
95
+
96
+ .. code-block:: python
97
+
98
+ from search_admin_autocomplete.admin import SearchAutoCompleteAdmin
99
+
100
+ class OrderAdmin(SearchAutoCompleteAdmin):
101
+ search_fields = [
102
+ 'order_number',
103
+ 'client__name', # ForeignKey → Client.name
104
+ 'client__email', # ForeignKey → Client.email
105
+ 'category__title', # ForeignKey → Category.title
106
+ ]
107
+
108
+ admin.site.register(Order, OrderAdmin)
109
+
110
+ The autocomplete will search and display values from both the model and its related models.
111
+
112
+ Configuration Options
113
+ =====================
114
+
115
+ .. code-block:: python
116
+
117
+ class MyModelAdmin(SearchAutoCompleteAdmin):
118
+ search_fields = ['name', 'client__name']
119
+ search_prefix = '__icontains' # Search operator (default: '__contains')
120
+ max_results = 20 # Max autocomplete results (default: 10)
121
+
122
+ Customization
123
+ =============
124
+
125
+ If you have a custom ``change_list.html``:
126
+
127
+ **admin.py**
128
+
129
+ .. code-block:: python
130
+
131
+ from search_admin_autocomplete.admin import SearchAutoCompleteAdmin
132
+
133
+ class MyModelAdmin(SearchAutoCompleteAdmin):
134
+ change_list_template = 'admin/custom-list.html'
135
+ search_fields = ['name', 'client__title']
136
+
137
+ admin.site.register(MyModel, MyModelAdmin)
138
+
139
+ **admin/custom-list.html**
140
+
141
+ .. code-block:: html
142
+
143
+ {% extends 'search_admin_autocomplete/change_list.html' %}
144
+
145
+ {% block object-tools %}
146
+ Your custom html...
147
+ {{ block.super }}
148
+ {% endblock %}
149
+
150
+ Running Tests
151
+ =============
152
+
153
+ .. code-block:: bash
154
+
155
+ cd example
156
+ python manage.py test search_admin_autocomplete
157
+
158
+ Changelog
159
+ =========
160
+
161
+ 0.3.0 (2026)
162
+ ------------
163
+ - **Forked** from archived ``django-search-admin-autocomplete``
164
+ - Added support for related field lookups (e.g., ``client__name``)
165
+ - Updated for Django 4+ and 5+ compatibility
166
+ - Modernized package configuration with ``pyproject.toml``
167
+ - Added comprehensive test suite (18 tests)
168
+
169
+ 0.2.1 and earlier
170
+ -----------------
171
+ - Original release by linevich (see `upstream repo <https://github.com/linevich/django-search-admin-autocomplete>`_)
@@ -0,0 +1,134 @@
1
+ Django-search-admin-autocomplete
2
+ ================================
3
+
4
+ .. image:: https://raw.githubusercontent.com/linevych/django-search-admin-autocomplete/master/doc/demo.gif
5
+
6
+ **This is a fork of** `django-search-admin-autocomplete <https://github.com/linevich/django-search-admin-autocomplete>`_ **(archived).** The original package is no longer maintained. This fork adds new features, modern Django support, and bug fixes.
7
+
8
+ Simple Django app that adds autocomplete search to the admin panel changelist view.
9
+
10
+ What's New
11
+ ----------
12
+
13
+ - **Related field search**: Search across ForeignKey relations (e.g., ``client__name``, ``category__title``)
14
+ - **Django 4+ / 5+ support**: Fixed deprecated ``url()`` imports
15
+ - **Modern build system**: ``pyproject.toml`` with hatchling (no more ``setup.py``)
16
+ - **Python 3.8–3.13** support
17
+ - **Comprehensive test suite** (18 tests)
18
+
19
+ Requirements
20
+ ============
21
+
22
+ - Python: 3.8+
23
+ - Django: 3.2+
24
+
25
+ Installation
26
+ ============
27
+
28
+ .. code-block:: bash
29
+
30
+ pip install django-listview-search-admin-autocomplete
31
+
32
+ .. code-block:: python
33
+
34
+ INSTALLED_APPS = [
35
+ ...
36
+ 'search_admin_autocomplete',
37
+ ...
38
+ ]
39
+
40
+ Usage
41
+ =====
42
+
43
+ Basic usage with direct fields:
44
+
45
+ .. code-block:: python
46
+
47
+ from search_admin_autocomplete.admin import SearchAutoCompleteAdmin
48
+
49
+ class MyModelAdmin(SearchAutoCompleteAdmin):
50
+ search_fields = ['name', 'description']
51
+
52
+ admin.site.register(MyModel, MyModelAdmin)
53
+
54
+ Related Field Support
55
+ =====================
56
+
57
+ Search across ForeignKey and related model fields using Django's ``__`` lookup syntax:
58
+
59
+ .. code-block:: python
60
+
61
+ from search_admin_autocomplete.admin import SearchAutoCompleteAdmin
62
+
63
+ class OrderAdmin(SearchAutoCompleteAdmin):
64
+ search_fields = [
65
+ 'order_number',
66
+ 'client__name', # ForeignKey → Client.name
67
+ 'client__email', # ForeignKey → Client.email
68
+ 'category__title', # ForeignKey → Category.title
69
+ ]
70
+
71
+ admin.site.register(Order, OrderAdmin)
72
+
73
+ The autocomplete will search and display values from both the model and its related models.
74
+
75
+ Configuration Options
76
+ =====================
77
+
78
+ .. code-block:: python
79
+
80
+ class MyModelAdmin(SearchAutoCompleteAdmin):
81
+ search_fields = ['name', 'client__name']
82
+ search_prefix = '__icontains' # Search operator (default: '__contains')
83
+ max_results = 20 # Max autocomplete results (default: 10)
84
+
85
+ Customization
86
+ =============
87
+
88
+ If you have a custom ``change_list.html``:
89
+
90
+ **admin.py**
91
+
92
+ .. code-block:: python
93
+
94
+ from search_admin_autocomplete.admin import SearchAutoCompleteAdmin
95
+
96
+ class MyModelAdmin(SearchAutoCompleteAdmin):
97
+ change_list_template = 'admin/custom-list.html'
98
+ search_fields = ['name', 'client__title']
99
+
100
+ admin.site.register(MyModel, MyModelAdmin)
101
+
102
+ **admin/custom-list.html**
103
+
104
+ .. code-block:: html
105
+
106
+ {% extends 'search_admin_autocomplete/change_list.html' %}
107
+
108
+ {% block object-tools %}
109
+ Your custom html...
110
+ {{ block.super }}
111
+ {% endblock %}
112
+
113
+ Running Tests
114
+ =============
115
+
116
+ .. code-block:: bash
117
+
118
+ cd example
119
+ python manage.py test search_admin_autocomplete
120
+
121
+ Changelog
122
+ =========
123
+
124
+ 0.3.0 (2026)
125
+ ------------
126
+ - **Forked** from archived ``django-search-admin-autocomplete``
127
+ - Added support for related field lookups (e.g., ``client__name``)
128
+ - Updated for Django 4+ and 5+ compatibility
129
+ - Modernized package configuration with ``pyproject.toml``
130
+ - Added comprehensive test suite (18 tests)
131
+
132
+ 0.2.1 and earlier
133
+ -----------------
134
+ - Original release by linevich (see `upstream repo <https://github.com/linevich/django-search-admin-autocomplete>`_)
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "django-listview-search-admin-autocomplete"
7
+ version = "0.3.0"
8
+ description = "Django admin autocomplete with related field support"
9
+ readme = "README.rst"
10
+ license = "MIT"
11
+ authors = [
12
+ { name = "linevich", email = "mail@linevich.net" },
13
+ ]
14
+ maintainers = [
15
+ { name = "Your Name", email = "your@email.com" },
16
+ ]
17
+ keywords = ["django", "admin", "autocomplete", "search"]
18
+ classifiers = [
19
+ "Development Status :: 4 - Beta",
20
+ "Environment :: Web Environment",
21
+ "Framework :: Django",
22
+ "Framework :: Django :: 3.2",
23
+ "Framework :: Django :: 4.2",
24
+ "Framework :: Django :: 5.0",
25
+ "Framework :: Django :: 5.1",
26
+ "Intended Audience :: Developers",
27
+ "License :: OSI Approved :: MIT License",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.8",
32
+ "Programming Language :: Python :: 3.9",
33
+ "Programming Language :: Python :: 3.10",
34
+ "Programming Language :: Python :: 3.11",
35
+ "Programming Language :: Python :: 3.12",
36
+ "Programming Language :: Python :: 3.13",
37
+ "Topic :: Internet :: WWW/HTTP",
38
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
39
+ ]
40
+ requires-python = ">=3.8"
41
+ dependencies = [
42
+ "Django>=3.2",
43
+ ]
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/linevich/django-search-admin-autocomplete"
47
+ Repository = "https://github.com/linevich/django-search-admin-autocomplete"
48
+ Documentation = "https://github.com/linevich/django-search-admin-autocomplete#readme"
49
+ Issues = "https://github.com/linevich/django-search-admin-autocomplete/issues"
50
+ Changelog = "https://github.com/linevich/django-search-admin-autocomplete/releases"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["search_admin_autocomplete"]
54
+
55
+ [tool.hatch.build.targets.sdist]
56
+ include = [
57
+ "/search_admin_autocomplete",
58
+ "/README.rst",
59
+ "/LICENSE",
60
+ ]
61
+
62
+ [tool.pytest.ini_options]
63
+ DJANGO_SETTINGS_MODULE = "example.project.settings"
64
+ pythonpath = ["."]
65
+ testpaths = ["search_admin_autocomplete"]
66
+
67
+ [tool.ruff]
68
+ target-version = "py38"
69
+ line-length = 120
70
+
71
+ [tool.ruff.lint]
72
+ select = ["E", "F", "W", "I"]
73
+
74
+
@@ -0,0 +1,91 @@
1
+ from functools import reduce
2
+ from operator import or_
3
+ from typing import List
4
+
5
+ from django.contrib import admin
6
+ from django.db.models import Q, Model
7
+ from django.http import HttpRequest
8
+
9
+ try:
10
+ from django.urls import reverse
11
+ except ImportError:
12
+ from django.core.urlresolvers import reverse # type: ignore
13
+
14
+ try:
15
+ from django.urls import re_path
16
+ except ImportError:
17
+ from django.conf.urls import url as re_path # type: ignore
18
+
19
+ from django.http.response import HttpResponse, JsonResponse, HttpResponseBadRequest
20
+ from django.urls.resolvers import URLPattern
21
+
22
+
23
+ class SearchAutoCompleteAdmin(admin.ModelAdmin):
24
+ """
25
+ Basic admin class that allows to enable search autocomplete for certain model.
26
+
27
+ Usage:
28
+
29
+ .. code-block:: python
30
+
31
+ class MyModelAdmin(SearchAutoCompleteAdmin)
32
+ search_fields = ['search_field', ]
33
+
34
+ admin.site.register(MyModel, MyModelAdmin)
35
+ """
36
+ change_list_template = 'search_admin_autocomplete/change_list.html'
37
+ search_fields = [] # type: List[str]
38
+ search_prefix = '__contains'
39
+ max_results = 10
40
+
41
+ def get_urls(self) -> List[URLPattern]:
42
+ urls = super(SearchAutoCompleteAdmin, self).get_urls()
43
+ api_urls = [re_path(r'^search/(?P<search_term>\w{0,50})$', self.search_api)]
44
+ return api_urls + urls
45
+
46
+ def search_api(self, request: HttpRequest, search_term: str) -> HttpResponse:
47
+ """
48
+ API view that perform search by search term for current model.
49
+ """
50
+ if len(self.search_fields) == 0:
51
+ return HttpResponseBadRequest(reason='Mo search_fields defined in {}'.format(self.__class__.__name__))
52
+
53
+ query = [Q(**{'{}{}'.format(field, self.search_prefix): search_term}) for field in self.search_fields]
54
+ # https://github.com/python/mypy/issues/4150
55
+ query = reduce(or_, query) # type: ignore
56
+ return JsonResponse(data=[{'keyword': self.get_instance_name(item), 'url': self.get_instance_url(item)}
57
+ for item in self.model.objects.filter(query)[0:self.max_results]], safe=False)
58
+
59
+ def _get_field_value(self, instance, field_name):
60
+ """Resolve field value supporting related field lookups like 'client__name'."""
61
+ parts = field_name.split('__')
62
+ obj = instance
63
+ for part in parts:
64
+ obj = getattr(obj, part, None)
65
+ if obj is None:
66
+ return None
67
+ return obj
68
+
69
+ def get_instance_name(self, instance: Model) -> str:
70
+ """
71
+ Format instance name based on value of search fields.
72
+ """
73
+ values = []
74
+
75
+ for field in self.search_fields:
76
+ value = self._get_field_value(instance, field)
77
+ if not value:
78
+ continue
79
+ values.append(str(value))
80
+
81
+ if not values:
82
+ return ""
83
+
84
+ return ", ".join(values)
85
+
86
+ def get_instance_url(self, instance: Model) -> str:
87
+ """
88
+ Returns url admin change view for model instance.
89
+ """
90
+ url_name = "admin:{}_{}_change".format(self.model._meta.app_label, str(self.model.__name__).lower())
91
+ return reverse(url_name, args=(instance.pk,))
@@ -0,0 +1,5 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class SearchAdminAutocompleteConfig(AppConfig):
5
+ name = 'search_admin_autocomplete'
@@ -0,0 +1,3 @@
1
+ from django.db import models
2
+
3
+ # Create your models here.