diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2009-12-09 16:07:21 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2009-12-09 16:07:21 +0000 |
| commit | eeb10d5f2c5375ec28b7761f9ea0fd4f1d2e4bd1 (patch) | |
| tree | 8fbe20cb1448eb57cbbbd08eddc937fc630aad1d /tests/modeltests/basic | |
| parent | bb428f3e86953d09df050b2614639f5c8a68840d (diff) | |
Optimised use of 'in' operator on QuerySet using an explicit __contains__ method.
Without this change, use of 'in' on a QuerySet resulted in ._result_cache
being fully populated, which sometimes is unnecessary work.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11803 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/basic')
| -rw-r--r-- | tests/modeltests/basic/models.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 2dbde58256..34bfc6a83e 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -211,6 +211,14 @@ True >>> Article.objects.get(id__exact=8) == Article.objects.get(id__exact=7) False +# You can use 'in' to test for membership... +>>> a8 in Article.objects.all() +True + +# ... but there will often be more efficient ways if that is all you need: +>>> Article.objects.filter(id=a8.id).exists() +True + # dates() returns a list of available dates of the given scope for the given field. >>> Article.objects.dates('pub_date', 'year') [datetime.datetime(2005, 1, 1, 0, 0)] |
