diff options
| author | seanhelvey <sean.helvey@gmail.com> | 2024-12-13 11:56:53 -0800 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-01-22 21:12:23 -0500 |
| commit | b1ffa9a9d78b0c2c5ad6ed5a1d84e380d5cfd010 (patch) | |
| tree | 0fcfd9b90c788e21e58cb9249f4119062b8bfc4e /django/contrib/admin/widgets.py | |
| parent | 3851601b2e080df34fb9227fe5d2fd43af604263 (diff) | |
Fixed #13883 -- Rendered named choice groups with <optgroup> in FilteredSelectMultiple.
This patch adds support for <optgroup>s in FilteredSelectMultiple widgets.
When a popup returns a new object, if the source field contains optgroup
choices, the optgroup is now also included in the response data.
Additionally, this adds error handling for invalid source_model parameters
to prevent crashes and display user-friendly error messages instead.
Co-authored-by: Michael McLarnon <mmclar@gmail.com>
Diffstat (limited to 'django/contrib/admin/widgets.py')
| -rw-r--r-- | django/contrib/admin/widgets.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index f5c3939012..67eac083e7 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -333,16 +333,24 @@ class RelatedFieldWidgetWrapper(forms.Widget): ) def get_context(self, name, value, attrs): - from django.contrib.admin.views.main import IS_POPUP_VAR, TO_FIELD_VAR + from django.contrib.admin.views.main import ( + IS_POPUP_VAR, + SOURCE_MODEL_VAR, + TO_FIELD_VAR, + ) rel_opts = self.rel.model._meta info = (rel_opts.app_label, rel_opts.model_name) related_field_name = self.rel.get_related_field().name + app_label = self.rel.field.model._meta.app_label + model_name = self.rel.field.model._meta.model_name + url_params = "&".join( "%s=%s" % param for param in [ (TO_FIELD_VAR, related_field_name), (IS_POPUP_VAR, 1), + (SOURCE_MODEL_VAR, f"{app_label}.{model_name}"), ] ) context = { |
