#24141: contains() method for QuerySets
-------------------------------------+-------------------------------------
     Reporter:  gormster             |                    Owner:
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  1                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by timgraham):

 * status:  closed => new
 * needs_docs:  0 => 1
 * resolution:  wontfix =>
 * needs_tests:  0 => 1


Comment:

 Oops. Sorry, Carl. I saw your comment "The main argument against
 `contains()`, I think, would just be that it's rarely if ever needed." and
 not the one before it "Adding this as a .contains() method to QuerySet is
 a reasonable feature request that's consistent with the current design
 philosophy".

 I am not sure if this proposal will lead to better code for anyone who
 doesn't read the docs or not. Since it hides the underlying fact of
 whether or not the QuerySet is cached, it seems to me that it won't
 necessarily be more intuitive to write code that's more efficient.  For
 example:
 {{{
 queryset = Foo.objects.all()
 for obj in range objs:
     if queryset.contains(obj):
        print("Found %s" % obj)
 }}}
 In the new example, my understanding is we'll get `len(obj)` queries,
 where as if we use `if obj in queryset`, we'll get 1 query. Please correct
 me if I'm wrong.

--
Ticket URL: <https://code.djangoproject.com/ticket/24141#comment:5>
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/066.c2b91f8a1944347ffe7ee0232e255e73%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to