Skip to content

Commit 98c8802

Browse files
authored
fix: autocomplete filter query (#1101)
1 parent 28a4394 commit 98c8802

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/unfold/contrib/filters/admin/mixins.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from django.contrib.admin.views.main import ChangeList
55
from django.core.validators import EMPTY_VALUES
66
from django.db.models import QuerySet
7+
from django.db.models.fields import BLANK_CHOICE_DASH, Field
78
from django.forms import ValidationError
89
from django.http import HttpRequest
910
from django.utils.translation import gettext_lazy as _
1011

12+
from unfold.admin import ModelAdmin
1113
from unfold.contrib.filters.forms import (
1214
AutocompleteDropdownForm,
1315
DropdownForm,
@@ -123,6 +125,16 @@ def choices(self, changelist: ChangeList) -> tuple[dict[str, Any], ...]:
123125

124126

125127
class AutocompleteMixin:
128+
def has_output(self) -> bool:
129+
return True
130+
131+
def field_choices(
132+
self, field: Field, request: HttpRequest, model_admin: ModelAdmin
133+
) -> list[tuple[str, str]]:
134+
return [
135+
("", BLANK_CHOICE_DASH),
136+
]
137+
126138
def choices(
127139
self, changelist: ChangeList
128140
) -> Generator[dict[str, AutocompleteDropdownForm], None, None]:

src/unfold/contrib/filters/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
self.fields[name] = self.field(
5353
label=label,
5454
required=False,
55-
queryset=field.remote_field.model.objects.all(),
55+
queryset=field.remote_field.model.objects,
5656
widget=self.widget(field, model_admin.admin_site),
5757
)
5858

@@ -61,7 +61,7 @@ class Media:
6161
"admin/js/vendor/jquery/jquery.js",
6262
"admin/js/vendor/select2/select2.full.js",
6363
"admin/js/jquery.init.js",
64-
"admin/js/select2.init.js",
64+
"unfold/js/select2.init.js",
6565
)
6666
css = {
6767
"screen": (

0 commit comments

Comments
 (0)