﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35330	The update of related objects fails in the admin when the related model is camel case.	Devin Cox	Devin Cox	"Related to Ticket #34789

To reproduce, take these models:

{{{
class TransitionState(models.Model):
    label = models.CharField(max_length=255)

    def __str__(self):
        return self.label

class Transition(models.Model):
    source = models.ManyToManyField(TransitionState, related_name=""transition_source"")
    target = models.ForeignKey(
        TransitionState, on_delete=models.CASCADE, related_name=""transition_target""
    )

}}}

and this admin:


{{{
class TransitionAdmin(admin.ModelAdmin):
    filter_horizontal = [""source""]

site.register(TransitionState)
site.register(Transition, TransitionAdmin)
}}}

When we add a ""Target"", we expect the ""available"" source to be populated with the new target. However, due to the camel casing of TransitionState, we cause `data-model-ref` to check `transitionstate` against `transition state`, and therefore does not pick up the match.

Proposed Change by @nessita as discussed in https://github.com/django/django/pull/17897:


{{{

diff --git a/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html b/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html
index 8e4356a95c..99b20545af 100644
--- a/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html
+++ b/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html
@@ -1,5 +1,5 @@
 {% load i18n static %}
-<div class=""related-widget-wrapper"" {% if not model_has_limit_choices_to %}data-model-ref=""{{ model }}""{% endif %}>
+<div class=""related-widget-wrapper"" {% if not model_has_limit_choices_to %}data-model-ref=""{{ model_name }}""{% endif %}>
     {{ rendered_widget }}
     {% block links %}
         {% spaceless %}
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index fc0cd941d1..9633ebb1a1 100644
--- a/django/contrib/admin/widgets.py
+++ b/django/contrib/admin/widgets.py
@@ -328,6 +328,7 @@ class RelatedFieldWidgetWrapper(forms.Widget):
             ""name"": name,
             ""url_params"": url_params,
             ""model"": rel_opts.verbose_name,
+            ""model_name"": rel_opts.model_name,
             ""can_add_related"": self.can_add_related,
             ""can_change_related"": self.can_change_related,
             ""can_delete_related"": self.can_delete_related,
}}}


"	Bug	closed	contrib.admin	5.0	Normal	fixed			Ready for checkin	1	0	0	0	1	1
