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/topics/db/aggregation.txt | 2 +- docs/topics/db/examples/many_to_many.txt | 102 +++++++++++++++---------------- docs/topics/db/examples/many_to_one.txt | 54 ++++++++-------- docs/topics/db/examples/one_to_one.txt | 12 ++-- docs/topics/db/models.txt | 12 ++-- docs/topics/forms/modelforms.txt | 2 +- 6 files changed, 92 insertions(+), 92 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/db/aggregation.txt b/docs/topics/db/aggregation.txt index 65a1eb7ee6..22c4e483df 100644 --- a/docs/topics/db/aggregation.txt +++ b/docs/topics/db/aggregation.txt @@ -79,7 +79,7 @@ In a hurry? Here's how to do common aggregate queries, assuming the models above >>> from django.db.models import Count >>> pubs = Publisher.objects.annotate(num_books=Count('book')) >>> pubs - [, , ...] + , , ...]> >>> pubs[0].num_books 73 diff --git a/docs/topics/db/examples/many_to_many.txt b/docs/topics/db/examples/many_to_many.txt index 79605ac158..cbf8da99e2 100644 --- a/docs/topics/db/examples/many_to_many.txt +++ b/docs/topics/db/examples/many_to_many.txt @@ -93,36 +93,36 @@ Create and add a ``Publication`` to an ``Article`` in one step using ``Article`` objects have access to their related ``Publication`` objects:: >>> a1.publications.all() - [] + ]> >>> a2.publications.all() - [, , , ] + , , , ]> ``Publication`` objects have access to their related ``Article`` objects:: >>> p2.article_set.all() - [] + ]> >>> p1.article_set.all() - [, ] + , ]> >>> Publication.objects.get(id=4).article_set.all() - [] + ]> Many-to-many relationships can be queried using :ref:`lookups across relationships `:: >>> Article.objects.filter(publications__id=1) - [, ] + , ]> >>> Article.objects.filter(publications__pk=1) - [, ] + , ]> >>> Article.objects.filter(publications=1) - [, ] + , ]> >>> Article.objects.filter(publications=p1) - [, ] + , ]> >>> Article.objects.filter(publications__title__startswith="Science") - [, ] + , ]> >>> Article.objects.filter(publications__title__startswith="Science").distinct() - [] + ]> The :meth:`~django.db.models.query.QuerySet.count` function respects :meth:`~django.db.models.query.QuerySet.distinct` as well:: @@ -134,57 +134,57 @@ The :meth:`~django.db.models.query.QuerySet.count` function respects 1 >>> Article.objects.filter(publications__in=[1,2]).distinct() - [, ] + , ]> >>> Article.objects.filter(publications__in=[p1,p2]).distinct() - [, ] + , ]> Reverse m2m queries are supported (i.e., starting at the table that doesn't have a :class:`~django.db.models.ManyToManyField`):: >>> Publication.objects.filter(id=1) - [] + ]> >>> Publication.objects.filter(pk=1) - [] + ]> >>> Publication.objects.filter(article__headline__startswith="NASA") - [, , , ] + , , , ]> >>> Publication.objects.filter(article__id=1) - [] + ]> >>> Publication.objects.filter(article__pk=1) - [] + ]> >>> Publication.objects.filter(article=1) - [] + ]> >>> Publication.objects.filter(article=a1) - [] + ]> >>> Publication.objects.filter(article__in=[1,2]).distinct() - [, , , ] + , , , ]> >>> Publication.objects.filter(article__in=[a1,a2]).distinct() - [, , , ] + , , , ]> Excluding a related item works as you would expect, too (although the SQL involved is a little complex):: >>> Article.objects.exclude(publications=p2) - [] + ]> If we delete a ``Publication``, its ``Articles`` won't be able to access it:: >>> p1.delete() >>> Publication.objects.all() - [, , ] + , , ]> >>> a1 = Article.objects.get(pk=1) >>> a1.publications.all() - [] + If we delete an ``Article``, its ``Publications`` won't be able to access it:: >>> a2.delete() >>> Article.objects.all() - [] + ]> >>> p2.article_set.all() - [] + Adding via the 'other' end of an m2m:: @@ -192,61 +192,61 @@ Adding via the 'other' end of an m2m:: >>> a4.save() >>> p2.article_set.add(a4) >>> p2.article_set.all() - [] + ]> >>> a4.publications.all() - [] + ]> Adding via the other end using keywords:: >>> new_article = p2.article_set.create(headline='Oxygen-free diet works wonders') >>> p2.article_set.all() - [, ] + , ]> >>> a5 = p2.article_set.all()[1] >>> a5.publications.all() - [] + ]> Removing ``Publication`` from an ``Article``:: >>> a4.publications.remove(p2) >>> p2.article_set.all() - [] + ]> >>> a4.publications.all() - [] + And from the other end:: >>> p2.article_set.remove(a5) >>> p2.article_set.all() - [] + >>> a5.publications.all() - [] + Relation sets can be assigned. Assignment clears any existing set members:: >>> a4.publications.all() - [] + ]> >>> a4.publications = [p3] >>> a4.publications.all() - [] + ]> Relation sets can be cleared:: >>> p2.article_set.clear() >>> p2.article_set.all() - [] + And you can clear from the other end:: >>> p2.article_set.add(a4, a5) >>> p2.article_set.all() - [, ] + , ]> >>> a4.publications.all() - [, ] + , ]> >>> a4.publications.clear() >>> a4.publications.all() - [] + >>> p2.article_set.all() - [] + ]> Recreate the ``Article`` and ``Publication`` we have deleted:: @@ -261,17 +261,17 @@ go:: >>> Publication.objects.filter(title__startswith='Science').delete() >>> Publication.objects.all() - [, ] + , ]> >>> Article.objects.all() - [, , , ] + , , , ]> >>> a2.publications.all() - [] + ]> Bulk delete some articles - references to deleted objects should go:: >>> q = Article.objects.filter(headline__startswith='Django') >>> print(q) - [] + ]> >>> q.delete() After the :meth:`~django.db.models.query.QuerySet.delete`, the @@ -279,9 +279,9 @@ After the :meth:`~django.db.models.query.QuerySet.delete`, the referenced objects should be gone:: >>> print(q) - [] + >>> p1.article_set.all() - [] + ]> An alternate to calling :meth:`~django.db.models.fields.related.RelatedManager.clear` is to assign the @@ -289,11 +289,11 @@ empty set:: >>> p1.article_set = [] >>> p1.article_set.all() - [] + >>> a2.publications = [p1, new_publication] >>> a2.publications.all() - [, ] + , ]> >>> a2.publications = [] >>> a2.publications.all() - [] + diff --git a/docs/topics/db/examples/many_to_one.txt b/docs/topics/db/examples/many_to_one.txt index 93cc3f093f..64f6ab1f1b 100644 --- a/docs/topics/db/examples/many_to_one.txt +++ b/docs/topics/db/examples/many_to_one.txt @@ -90,7 +90,7 @@ Create a new article, and add it to the article set:: >>> new_article2.reporter.id 1 >>> r.article_set.all() - [, , ] + , , ]> Add the same article to a different article set - check that it moves:: @@ -108,9 +108,9 @@ Adding an object of the wrong type raises TypeError:: TypeError: 'Article' instance expected >>> r.article_set.all() - [, ] + , ]> >>> r2.article_set.all() - [] + ]> >>> r.article_set.count() 2 @@ -126,56 +126,56 @@ Use double underscores to separate relationships. This works as many levels deep as you want. There's no limit. For example:: >>> r.article_set.filter(headline__startswith='This') - [] + ]> # Find all Articles for any Reporter whose first name is "John". >>> Article.objects.filter(reporter__first_name='John') - [, ] + , ]> Exact match is implied here:: >>> Article.objects.filter(reporter__first_name='John') - [, ] + , ]> Query twice over the related field. This translates to an AND condition in the WHERE clause:: >>> Article.objects.filter(reporter__first_name='John', reporter__last_name='Smith') - [, ] + , ]> For the related lookup you can supply a primary key value or pass the related object explicitly:: >>> Article.objects.filter(reporter__pk=1) - [, ] + , ]> >>> Article.objects.filter(reporter=1) - [, ] + , ]> >>> Article.objects.filter(reporter=r) - [, ] + , ]> >>> Article.objects.filter(reporter__in=[1,2]).distinct() - [, , ] + , , ]> >>> Article.objects.filter(reporter__in=[r,r2]).distinct() - [, , ] + , , ]> You can also use a queryset instead of a literal list of instances:: >>> Article.objects.filter(reporter__in=Reporter.objects.filter(first_name='John')).distinct() - [, ] + , ]> Querying in the opposite direction:: >>> Reporter.objects.filter(article__pk=1) - [] + ]> >>> Reporter.objects.filter(article=1) - [] + ]> >>> Reporter.objects.filter(article=a) - [] + ]> >>> Reporter.objects.filter(article__headline__startswith='This') - [, , ] + , , ]> >>> Reporter.objects.filter(article__headline__startswith='This').distinct() - [] + ]> Counting in the opposite direction works in conjunction with distinct():: @@ -187,30 +187,30 @@ Counting in the opposite direction works in conjunction with distinct():: Queries can go round in circles:: >>> Reporter.objects.filter(article__reporter__first_name__startswith='John') - [, , , ] + , , , ]> >>> Reporter.objects.filter(article__reporter__first_name__startswith='John').distinct() - [] + ]> >>> Reporter.objects.filter(article__reporter=r).distinct() - [] + ]> If you delete a reporter, his articles will be deleted (assuming that the ForeignKey was defined with :attr:`django.db.models.ForeignKey.on_delete` set to ``CASCADE``, which is the default):: >>> Article.objects.all() - [, , ] + , , ]> >>> Reporter.objects.order_by('first_name') - [, ] + , ]> >>> r2.delete() >>> Article.objects.all() - [, ] + , ]> >>> Reporter.objects.order_by('first_name') - [] + ]> You can delete using a JOIN in the query:: >>> Reporter.objects.filter(article__headline__startswith='This').delete() >>> Reporter.objects.all() - [] + >>> Article.objects.all() - [] + diff --git a/docs/topics/db/examples/one_to_one.txt b/docs/topics/db/examples/one_to_one.txt index dbf46fc079..7e373a98e1 100644 --- a/docs/topics/db/examples/one_to_one.txt +++ b/docs/topics/db/examples/one_to_one.txt @@ -106,13 +106,13 @@ that there are two restaurants - Ace Hardware the Restaurant was created in the call to r.place = p2:: >>> Restaurant.objects.all() - [, ] + , ]> Place.objects.all() returns all Places, regardless of whether they have Restaurants:: >>> Place.objects.order_by('name') - [, ] + , ]> You can query the models using :ref:`lookups across relationships `:: @@ -121,9 +121,9 @@ You can query the models using :ref:`lookups across relationships >> Restaurant.objects.get(place__pk=1) >>> Restaurant.objects.filter(place__name__startswith="Demon") - [] + ]> >>> Restaurant.objects.exclude(place__address__contains="Ashland") - [] + ]> This of course works in reverse:: @@ -146,6 +146,6 @@ Add a Waiter to the Restaurant:: Query the waiters:: >>> Waiter.objects.filter(restaurant__place=p1) - [] + ]> >>> Waiter.objects.filter(restaurant__place__name__startswith="Demon") - [] + ]> diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt index 99945d4287..586ec66927 100644 --- a/docs/topics/db/models.txt +++ b/docs/topics/db/models.txt @@ -501,14 +501,14 @@ the intermediate model:: ... invite_reason="Needed a new drummer.") >>> m1.save() >>> beatles.members.all() - [] + ]> >>> ringo.group_set.all() - [] + ]> >>> m2 = Membership.objects.create(person=paul, group=beatles, ... date_joined=date(1960, 8, 1), ... invite_reason="Wanted to form a band.") >>> beatles.members.all() - [, ] + , ]> Unlike normal many-to-many fields, you *can't* use ``add``, ``create``, or assignment (i.e., ``beatles.members = [...]``) to create relationships:: @@ -537,7 +537,7 @@ used to remove all many-to-many relationships for an instance:: >>> beatles.members.clear() >>> # Note that this deletes the intermediate model instances >>> Membership.objects.all() - [] + Once you have established the many-to-many relationships by creating instances of your intermediate model, you can issue queries. Just as with normal @@ -546,7 +546,7 @@ many-to-many-related model:: # Find all the groups with a member whose name starts with 'Paul' >>> Group.objects.filter(members__name__startswith='Paul') - [] + ]> As you are using an intermediate model, you can also query on its attributes:: @@ -554,7 +554,7 @@ As you are using an intermediate model, you can also query on its attributes:: >>> Person.objects.filter( ... group__name='The Beatles', ... membership__date_joined__gt=date(1961,1,1)) - [ If you need to access a membership's information you may do so by directly querying the ``Membership`` model:: diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index 6370636d4e..189336119e 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -912,7 +912,7 @@ extra forms displayed. ``max_num`` does not prevent existing objects from being displayed:: >>> Author.objects.order_by('name') - [, , ] + , , ]> >>> AuthorFormSet = modelformset_factory(Author, fields=('name',), max_num=1) >>> formset = AuthorFormSet(queryset=Author.objects.order_by('name')) -- cgit v1.3