#35330: The update of related objects fails in the admin when the related model 
has
a name in camel case.
-----------------------------------------+----------------------------
               Reporter:  devin13cox     |          Owner:  devin13cox
                   Type:  Bug            |         Status:  assigned
              Component:  contrib.admin  |        Version:  5.0
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  1
                  UI/UX:  1              |
-----------------------------------------+----------------------------
 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,
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35330>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e78b81c80-f1688a1d-6ff6-4aa9-9b11-a17ead8946a1-000000%40eu-central-1.amazonses.com.

Reply via email to