Opened 5 years ago

Closed 4 years ago

#17156 closed Cleanup/optimization (fixed)

QuerySet.__contains__ needs documentation

Reported by: Thomas Güttler Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: hv@…, sebastian.goll@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation should explain what happens in this code:

if obj in queryset:
    ....

If queryset is huge, the above code can be very slow.

If you want to run the code in the database, you should use this:

if queryset.filter(pk=obj.pk).exists():
    ....

Related discussion: http://groups.google.com/group/django-users/browse_thread/thread/5a8196ff1086f4ae/530548a127a6e3ca

Can someone please provide a patch for the documentation. I am not a native speaker, and won't find the right words.

Change History (4)

comment:1 Changed 5 years ago by Luke Plant

Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by Sebastian Goll

Cc: sebastian.goll@… added

comment:4 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In [d823bb790d3b70e19e7f8bc7cfb11f3a1728a799]:

Fixed #17156 -- Added documentation examples for exists()

Thanks mrmagooey for the draft patch.

Note: See TracTickets for help on using tickets.
Back to Top