#16647: Default filters: pacth to add  QuerySet support for random plus a new
shuffle filter
-------------------------------------+-------------------------------------
               Reporter:  h3         |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |      Component:  Template system
              Milestone:             |       Severity:  Normal
                Version:  1.3        |       Keywords:
             Resolution:             |      Has patch:  1
           Triage Stage:  Design     |    Needs tests:  1
  decision needed                    |  Easy pickings:  0
    Needs documentation:  1          |
Patch needs improvement:  1          |
                  UI/UX:  0          |
-------------------------------------+-------------------------------------

Comment (by h3):

 > If the queryset has already been evaluated, you could just transform it
 to a list and perform the ordinary random/shuffle operations on that, I
 suppose... would that be faster?

 I will have to make some tests to tell


 > I am not sure this is a good idea. The problem is that
 qs.order_by('?')[0] might be really expensive. If I am not mistaken, the
 DB must go through the whole result set and sort everything. Even if the
 DB returns just one row, that can be expensive. I am afraid that users of
 random do not realize this, as how could a fetch of just a single object
 cost much...
 >
 > Also, in the patch you use len(qs). That means the queryset gets
 evaluated (or at least count(*) is evaluated) there. try - except
 indexerror is better.

 This strengthen my feeling that these functionality (random/shuffle filter
 for qs) should really be included by django core.

 What I did was the "obvious" way of doing it and it's how a lot of django
 developers will implement it the day they'll need this functionality.

 Now the question is, what's the optimal way to do it..

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16647#comment:4>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to