#32466: Closed ticket #29138 breaks autocomplete for inherited models
-----------------------------------------+------------------------------
               Reporter:  dlis           |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  contrib.admin  |        Version:  3.2
               Severity:  Normal         |       Keywords:  autocomplete
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------------
 Unfortunately, Closed ticket #29138 breaks autocomplete for the case of
 inherited models. For example, we have the following code:

 {{{
 # models.py
 from django.db import models

 class Tag(models.Model):
     pass

 class Foo(models.Model):
     tags = models.ManyToManyField(Tag)

 class Bar(Foo):
     pass


 # admin.py
 from django.contrib import admin
 from . import models

 @admin.register(models.Foo)
 class Foo(admin.ModelAdmin):
     autocomplete_fields = ('tags',)

 @admin.register(models.Bar)
 class Bar(admin.ModelAdmin):
     autocomplete_fields = ('tags',)
 }}}

 Now, autocomplete for `admin.Foo` will work but not for `admin.Bar`
 because `django.contrib.admin.widgets.AutocompleteMixin.optgroups()`
 calculates a wrong value of a variable `to_field_name`, namely `foo_ptr`
 instead of `id`, whereupon following look up at
 `self.choices.queryset.using(self.db).filter(**{'%s__in' % to_field_name:
 selected_choices})` raises an exception because `models.Tag` does not have
 `foo_ptr`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32466>
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/047.64b996d5b0f1696355d1a39571d9d07a%40djangoproject.com.

Reply via email to