Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(generic): use dal widget only for models with autocomplete endpoint #772

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions apis_core/generic/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from crispy_forms.layout import Submit
from dal import autocomplete
from apis_core.generic.forms.fields import ModelImportChoiceField
from apis_core.generic.abc import GenericModel


class GenericImportForm(forms.Form):
Expand Down Expand Up @@ -85,8 +86,9 @@ def __init__(self, *args, **kwargs):
ct = ContentType.objects.get_for_model(
self.fields[field]._queryset.model
)
url = reverse("apis_core:generic:autocomplete", args=[ct])
self.fields[field].widget = override_fieldtypes[clsname](
url, attrs={"data-html": True}
)
self.fields[field].widget.choices = self.fields[field].choices
if issubclass(ct.model_class(), GenericModel):
url = reverse("apis_core:generic:autocomplete", args=[ct])
self.fields[field].widget = override_fieldtypes[clsname](
url, attrs={"data-html": True}
)
self.fields[field].widget.choices = self.fields[field].choices
Loading