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/models/database-functions.txt | 2 +- docs/ref/models/querysets.txt | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'docs/ref/models') 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