#27729: Add a method to evaluate QuerySets.
-------------------------------------+-------------------------------------
     Reporter:  AlbinLindskog        |                    Owner:  Albin
                                     |  Lindskog
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by AlbinLindskog):

 * needs_docs:  0 => 1


Old description:

> I would often like to evaluate a queryset once, i.e. fetch it to local
> memory, and then repeatedly perform various operations on it, e.g.
> filtering.
>
> As i currently stands to do that I can either:
>
>  - Drop to some native python data structure, e.g. a list, but I find the
> Django ORM syntax more understandable.
>  - Not evaluate the QuerySet, but then the performance will take a hit as
> each operation will query the database.
>  - I could also force the QuerySet to evaluate, for example by calling
> len() or bool(), but unless you are familiar with how Django handels
> QuerySets it's not clear what's being accomplished behind the scenes.
>  - Lastly I can use the internal method _fetch_all(), which is bad
> practise. Secondly, because it does not return a QuerySet you can not
> chain it.
>
> Needless to say, I don't like either option. I think the QuerySet class
> needs a evaluate()-method, which does, as the name suggest, evaluates the
> QuerySet.
>
> I've added a patch that accomplishes this. Could I get some feedback on
> my suggestion and code? If the feedback is positive I'll move to update
> the documentation and create a pull request.

New description:

 I would often like to evaluate a queryset once, i.e. fetch it to local
 memory, and then repeatedly perform various operations on it, e.g.
 filtering.

 As i currently stands to do that I can either:

  - Drop to some native python data structure, e.g. a list, but I find the
 Django ORM syntax more understandable.
  - Not evaluate the QuerySet, but then the performance will take a hit as
 each operation will query the database.
  - I could also force the QuerySet to evaluate, for example by calling
 len() or bool(), but unless you are familiar with how Django handels
 QuerySets it's not clear what's being accomplished behind the scenes.
  - Lastly I can use the internal method _fetch_all(), which is bad
 practise. Secondly, because it does not return a QuerySet you can not
 chain it.

 Needless to say, I don't like either option. I think the QuerySet class
 needs a evaluate()-method, which does, as the name suggest, evaluates the
 QuerySet.

 I've added a patch that accomplishes this. Could I get some feedback on my
 suggestion and code? If the feedback is positive I'll move to update the
 documentation and create a pull request.

 I should clarify that I have assign this ticket to myself.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27729#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.1fa0fdd2d6e466ffedba0cc7f12c6a32%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to