From e0837f2cb12de5e95e621d19b186b0da43bcdee2 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 5 Oct 2015 19:07:34 -0400 Subject: Fixed #25508 -- Modified QuerySet.__repr__() to disambiguate it from a list. --- docs/ref/contrib/contenttypes.txt | 6 +-- docs/ref/contrib/gis/tutorial.txt | 10 ++--- docs/ref/contrib/postgres/fields.txt | 78 ++++++++++++++++----------------- docs/ref/contrib/postgres/functions.txt | 2 +- docs/ref/models/database-functions.txt | 2 +- docs/ref/models/querysets.txt | 34 +++++++------- 6 files changed, 65 insertions(+), 67 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt index 7e033a8913..4a8fa22f4b 100644 --- a/docs/ref/contrib/contenttypes.txt +++ b/docs/ref/contrib/contenttypes.txt @@ -382,7 +382,7 @@ be used to retrieve their associated ``TaggedItems``:: >>> t2 = TaggedItem(content_object=b, tag='python') >>> t2.save() >>> b.tags.all() - [, ] + , ]> Defining :class:`~django.contrib.contenttypes.fields.GenericRelation` with ``related_query_name`` set allows querying from the related object:: @@ -394,7 +394,7 @@ from ``TaggedItem``:: >>> # Get all tags belonging to books containing `django` in the url >>> TaggedItem.objects.filter(bookmarks__url__contains='django') - [, ] + , ]> Just as :class:`~django.contrib.contenttypes.fields.GenericForeignKey` accepts the names of the content-type and object-ID fields as @@ -418,7 +418,7 @@ same types of lookups manually:: >>> bookmark_type = ContentType.objects.get_for_model(b) >>> TaggedItem.objects.filter(content_type__pk=bookmark_type.id, ... object_id=b.id) - [, ] + , ]> Note that if the model in a :class:`~django.contrib.contenttypes.fields.GenericRelation` uses a diff --git a/docs/ref/contrib/gis/tutorial.txt b/docs/ref/contrib/gis/tutorial.txt index bf2bc28d9b..793e17a34e 100644 --- a/docs/ref/contrib/gis/tutorial.txt +++ b/docs/ref/contrib/gis/tutorial.txt @@ -588,9 +588,8 @@ Consortium (OGC). [#]_ Import the ``WorldBorder`` model, and perform a ``contains`` lookup using the ``pnt_wkt`` as the parameter:: >>> from world.models import WorldBorder - >>> qs = WorldBorder.objects.filter(mpoly__contains=pnt_wkt) - >>> qs - [] + >>> WorldBorder.objects.filter(mpoly__contains=pnt_wkt) + ]> Here, you retrieved a ``QuerySet`` with only one model: the border of the United States (exactly what you would expect). @@ -602,8 +601,7 @@ of a queryset:: >>> from django.contrib.gis.geos import Point >>> pnt = Point(12.4604, 43.9420) - >>> sm = WorldBorder.objects.get(mpoly__intersects=pnt) - >>> sm + >>> WorldBorder.objects.get(mpoly__intersects=pnt) The ``contains`` and ``intersects`` lookups are just a subset of the @@ -638,7 +636,7 @@ of abstraction:: "world_worldborder"."mpoly" FROM "world_worldborder" WHERE ST_Intersects("world_worldborder"."mpoly", ST_Transform(%s, 4326)) >>> qs # printing evaluates the queryset - [] + ]> __ http://spatialreference.org/ref/epsg/32140/ diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index 587c44a435..defd670e12 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -120,13 +120,13 @@ data. It uses the SQL operator ``@>``. For example:: >>> Post.objects.create(name='Third post', tags=['tutorial', 'django']) >>> Post.objects.filter(tags__contains=['thoughts']) - [, ] + , ]> >>> Post.objects.filter(tags__contains=['django']) - [, ] + , ]> >>> Post.objects.filter(tags__contains=['django', 'thoughts']) - [] + ]> .. fieldlookup:: arrayfield.contained_by @@ -142,10 +142,10 @@ passed. It uses the SQL operator ``<@``. For example:: >>> Post.objects.create(name='Third post', tags=['tutorial', 'django']) >>> Post.objects.filter(tags__contained_by=['thoughts', 'django']) - [, ] + , ]> >>> Post.objects.filter(tags__contained_by=['thoughts', 'django', 'tutorial']) - [, , ] + , , ]> .. fieldlookup:: arrayfield.overlap @@ -160,10 +160,10 @@ the SQL operator ``&&``. For example:: >>> Post.objects.create(name='Third post', tags=['tutorial', 'django']) >>> Post.objects.filter(tags__overlap=['thoughts']) - [, ] + , ]> >>> Post.objects.filter(tags__overlap=['thoughts', 'tutorial']) - [, , ] + , , ]> .. fieldlookup:: arrayfield.len @@ -177,7 +177,7 @@ available for :class:`~django.db.models.IntegerField`. For example:: >>> Post.objects.create(name='Second post', tags=['thoughts']) >>> Post.objects.filter(tags__len=1) - [] + ]> .. fieldlookup:: arrayfield.index @@ -194,13 +194,13 @@ example:: >>> Post.objects.create(name='Second post', tags=['thoughts']) >>> Post.objects.filter(tags__0='thoughts') - [, ] + , ]> >>> Post.objects.filter(tags__1__iexact='Django') - [] + ]> >>> Post.objects.filter(tags__276='javascript') - [] + .. note:: @@ -222,10 +222,10 @@ lookups available after the transform do not change. For example:: >>> Post.objects.create(name='Third post', tags=['django', 'python', 'thoughts']) >>> Post.objects.filter(tags__0_1=['thoughts']) - [] + ]> >>> Post.objects.filter(tags__0_2__contains='thoughts') - [, ] + , ]> .. note:: @@ -320,12 +320,12 @@ To query based on a given key, you simply use that key as the lookup name:: >>> Dog.objects.create(name='Meg', data={'breed': 'collie'}) >>> Dog.objects.filter(data__breed='collie') - [] + ]> You can chain other lookups after key lookups:: >>> Dog.objects.filter(data__breed__contains='l') - [, ] + , ]> If the key you wish to query by clashes with the name of another lookup, you need to use the :lookup:`hstorefield.contains` lookup instead. @@ -352,10 +352,10 @@ field. It uses the SQL operator ``@>``. For example:: >>> Dog.objects.create(name='Fred', data={}) >>> Dog.objects.filter(data__contains={'owner': 'Bob'}) - [, ] + , ]> >>> Dog.objects.filter(data__contains={'breed': 'collie'}) - [] + ]> .. fieldlookup:: hstorefield.contained_by @@ -372,10 +372,10 @@ example:: >>> Dog.objects.create(name='Fred', data={}) >>> Dog.objects.filter(data__contained_by={'breed': 'collie', 'owner': 'Bob'}) - [, ] + , ]> >>> Dog.objects.filter(data__contained_by={'breed': 'collie'}) - [] + ]> .. fieldlookup:: hstorefield.has_key @@ -389,7 +389,7 @@ Returns objects where the given key is in the data. Uses the SQL operator >>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': 'Bob'}) >>> Dog.objects.filter(data__has_key='owner') - [] + ]> .. fieldlookup:: hstorefield.has_any_keys @@ -406,7 +406,7 @@ operator ``?|``. For example:: >>> Dog.objects.create(name='Fred', data={}) >>> Dog.objects.filter(data__has_any_keys=['owner', 'breed']) - [, ] + , ]> .. fieldlookup:: hstorefield.has_keys @@ -420,7 +420,7 @@ Returns objects where all of the given keys are in the data. Uses the SQL operat >>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': 'Bob'}) >>> Dog.objects.filter(data__has_keys=['breed', 'owner']) - [] + ]> .. fieldlookup:: hstorefield.keys @@ -437,7 +437,7 @@ in conjunction with lookups on >>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': 'Bob'}) >>> Dog.objects.filter(data__keys__overlap=['breed', 'toy']) - [, ] + , ]> .. fieldlookup:: hstorefield.values @@ -454,7 +454,7 @@ using in conjunction with lookups on >>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': 'Bob'}) >>> Dog.objects.filter(data__values__contains=['collie']) - [] + ]> JSONField --------- @@ -521,18 +521,18 @@ name:: >>> Dog.objects.create(name='Meg', data={'breed': 'collie'}) >>> Dog.objects.filter(data__breed='collie') - [] + ]> Multiple keys can be chained together to form a path lookup:: >>> Dog.objects.filter(data__owner__name='Bob') - [] + ]> If the key is an integer, it will be interpreted as an index lookup in an array:: >>> Dog.objects.filter(data__owner__other_pets__0__name='Fishy') - [] + ]> If the key you wish to query by clashes with the name of another lookup, use the :lookup:`jsonfield.contains` lookup instead. @@ -673,7 +673,7 @@ contains '''''''' >>> Event.objects.filter(ages__contains=NumericRange(4, 5)) - [] + ]> .. fieldlookup:: rangefield.contained_by @@ -681,7 +681,7 @@ contained_by '''''''''''' >>> Event.objects.filter(ages__contained_by=NumericRange(0, 15)) - [] + ]> .. versionadded 1.9 @@ -697,7 +697,7 @@ contained_by ... timezone.now() - datetime.timedelta(hours=1), ... timezone.now() + datetime.timedelta(hours=1), ... ) - [] + ]> .. fieldlookup:: rangefield.overlap @@ -705,7 +705,7 @@ overlap ''''''' >>> Event.objects.filter(ages__overlap=NumericRange(8, 12)) - [] + ]> Comparison functions ~~~~~~~~~~~~~~~~~~~~ @@ -726,7 +726,7 @@ all the points in the returned range are less than all those in the passed range. >>> Event.objects.filter(ages__fully_lt=NumericRange(11, 15)) - [] + ]> .. fieldlookup:: rangefield.fully_gt @@ -738,7 +738,7 @@ the all the points in the returned range are greater than all those in the passed range. >>> Event.objects.filter(ages__fully_gt=NumericRange(11, 15)) - [] + ]> .. fieldlookup:: rangefield.not_lt @@ -750,7 +750,7 @@ is the lower bound of the returned range is at least the lower bound of the passed range. >>> Event.objects.filter(ages__not_lt=NumericRange(0, 15)) - [, ] + , ]> .. fieldlookup:: rangefield.not_gt @@ -762,7 +762,7 @@ is the upper bound of the returned range is at most the upper bound of the passed range. >>> Event.objects.filter(ages__not_gt=NumericRange(3, 10)) - [] + ]> .. fieldlookup:: rangefield.adjacent_to @@ -772,7 +772,7 @@ adjacent_to The returned ranges share a bound with the passed range. >>> Event.objects.filter(ages__adjacent_to=NumericRange(10, 21)) - [, ] + , ]> Querying using the bounds ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -789,7 +789,7 @@ Returned objects have the given lower bound. Can be chained to valid lookups for the base field. >>> Event.objects.filter(ages__startswith=21) - [] + ]> .. fieldlookup:: rangefield.endswith @@ -800,7 +800,7 @@ Returned objects have the given upper bound. Can be chained to valid lookups for the base field. >>> Event.objects.filter(ages__endswith=10) - [] + ]> .. fieldlookup:: rangefield.isempty @@ -811,7 +811,7 @@ Returned objects are empty ranges. Can be chained to valid lookups for a :class:`~django.db.models.BooleanField`. >>> Event.objects.filter(ages__isempty=True) - [] + Defining your own range types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/ref/contrib/postgres/functions.txt b/docs/ref/contrib/postgres/functions.txt index c97af99bfb..f4abdc2c17 100644 --- a/docs/ref/contrib/postgres/functions.txt +++ b/docs/ref/contrib/postgres/functions.txt @@ -28,4 +28,4 @@ Usage example:: >>> from django.contrib.postgres.functions import TransactionNow >>> Article.objects.filter(published__lte=TransactionNow()) - [] + ]> diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 9c9f2641b9..fc3f25dd29 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -226,7 +226,7 @@ Usage example:: >>> from django.db.models.functions import Now >>> Article.objects.filter(published__lte=Now()) - [] + ]> .. admonition:: PostgreSQL considerations diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index ebb9019784..0887e94729 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -513,11 +513,11 @@ objects:: # This list contains a Blog object. >>> Blog.objects.filter(name__startswith='Beatles') - [] + ]> # This list contains a dictionary. >>> Blog.objects.filter(name__startswith='Beatles').values() - [{'id': 1, 'name': 'Beatles Blog', 'tagline': 'All the latest Beatles news.'}] + The ``values()`` method takes optional positional arguments, ``*fields``, which specify field names to which the ``SELECT`` should be limited. If you specify @@ -528,9 +528,9 @@ contain a key and value for every field in the database table. Example:: >>> Blog.objects.values() - [{'id': 1, 'name': 'Beatles Blog', 'tagline': 'All the latest Beatles news.'}], + >>> Blog.objects.values('id', 'name') - [{'id': 1, 'name': 'Beatles Blog'}] + A few subtleties that are worth mentioning: @@ -546,13 +546,13 @@ A few subtleties that are worth mentioning: For example:: >>> Entry.objects.values() - [{'blog_id': 1, 'headline': 'First Entry', ...}, ...] + >>> Entry.objects.values('blog') - [{'blog': 1}, ...] + >>> Entry.objects.values('blog_id') - [{'blog_id': 1}, ...] + * When using ``values()`` together with :meth:`distinct()`, be aware that ordering can affect the results. See the note in :meth:`distinct` for @@ -585,9 +585,9 @@ individualism. You can also refer to fields on related models with reverse relations through ``OneToOneField``, ``ForeignKey`` and ``ManyToManyField`` attributes:: - Blog.objects.values('name', 'entry__headline') - [{'name': 'My blog', 'entry__headline': 'An entry'}, - {'name': 'My blog', 'entry__headline': 'Another entry'}, ...] + >>> Blog.objects.values('name', 'entry__headline') + .. warning:: @@ -717,7 +717,7 @@ is an instance of ``EmptyQuerySet``. Examples:: >>> Entry.objects.none() - [] + >>> from django.db.models.query import EmptyQuerySet >>> isinstance(Entry.objects.none(), EmptyQuerySet) True @@ -3015,11 +3015,11 @@ as the string based lookups passed to :meth:`~django.db.models.query.QuerySet.prefetch_related()`. For example: >>> Question.objects.prefetch_related(Prefetch('choice_set')).get().choice_set.all() - [, , ] + , , ]> # This will only execute two queries regardless of the number of Question # and Choice objects. >>> Question.objects.prefetch_related(Prefetch('choice_set')).all() - [] + ]> The ``queryset`` argument supplies a base ``QuerySet`` for the given lookup. This is useful to further filter down the prefetch operation, or to call @@ -3028,19 +3028,19 @@ relation, hence reducing the number of queries even further: >>> voted_choices = Choice.objects.filter(votes__gt=0) >>> voted_choices - [] + ]> >>> prefetch = Prefetch('choice_set', queryset=voted_choices) >>> Question.objects.prefetch_related(prefetch).get().choice_set.all() - [] + ]> The ``to_attr`` argument sets the result of the prefetch operation to a custom attribute: >>> prefetch = Prefetch('choice_set', queryset=voted_choices, to_attr='voted_choices') >>> Question.objects.prefetch_related(prefetch).get().voted_choices - [] + ]> >>> Question.objects.prefetch_related(prefetch).get().choice_set.all() - [, , ] + , , ]> .. note:: -- cgit v1.3