#31295: Avoid Select widget triggering additional query when using
ModelChoiceIterator.
--------------------------------------+------------------------------------
     Reporter:  Aurélien Pardon       |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Forms                 |                  Version:  2.2
     Severity:  Normal                |               Resolution:
     Keywords:  Model                 |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Aurélien Pardon):

 Hi Carlton,

 Thanks for your answer. I'm afraid the code you proposed won't work, I
 just tested it. I will try to think about a solution.

 The difficulty is that when rendering the widget, we need '''before
 rendering the options''' (and thus iterate over the
 ModelChoiceFieldIterator/fetch the data from the DB) if the HTML attribute
 {{{required}}} should be used.
 And we also don't want to cache the query, for memory usage performance.

 I think of two different solutions :
  * defer the presence of the {{{required}}} attribute after the iteration
 for the <options>. During this iteration, we store the fact that the first
 option allows or not the {{{required}}} attribute. After the rendering of
 the options, we put afterwards (or not) the {{{required}}} attribute.
 Maybe with a placeholder replaced by a regexp? I find this quite ugly.
  *  Maybe the ModelChoiceIterator may cache it's first value? It should
 not take a lot of memory. I don't think it will work because I assume
 that, for efficiency, multiple rows are fetched from the database, if you
 want to cache the first value for an ulterior iteration, you also have to
 cache the rest of the rows until <options> are iterated.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31295#comment:13>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.a0ce695521035444e58fe2d59a6dc579%40djangoproject.com.

Reply via email to