#30256: autocomplete_fields cause one or two extra queries for each field wth
foreign key or many to many relation
-------------------------------------------+------------------------
               Reporter:  George Tantiras  |          Owner:  nobody
                   Type:  Uncategorized    |         Status:  new
              Component:  Uncategorized    |        Version:  2.1
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 The following model:

 models.py
 {{{#!python

 class Child3(models.Model):
     key = models.ForeignKey(Master, on_delete=models.PROTECT)
     child_keys = models.ManyToManyField(Child2)
     boolean = models.BooleanField()

 }}}

 admin.py

 {{{#!python

 @admin.register(models.Child3)
 class Child3Admin(admin.ModelAdmin):
     search_fields = ('id', )
     autocomplete_fields = ('key', 'child_keys')
     # form = forms.Child3Form  # Uncomment to enable django-autocomplete-
 light

 }}}

 When visiting the url of instance with id 1:
 http://127.0.0.1:8000/admin/inl/child3/1/change/

 The queries count varies as follows:

 no autocomplete feature: 3 queries
 with autocomplete_fields enabled: 6 queries
 with django-autocomplete-light enabled: 3 queries


 I have not calculated the contentype query that sometimes appears and
 sometimes not.

 When the above model is used as inline to another model the queries for
 each related instance accumulate.

 I have uploaded the [https://github.com/raratiru/autobug  autobug app ]
 which illustrates the above using 4 related models using foreign keys and
 many to many fields.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30256>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.219dd0bc2eb22cdb810b98bc1c7a30f1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to