Ticket #17605: 17605-5.diff

File 17605-5.diff, 24.7 KB (added by Ramiro Morales, 13 years ago)

zsiciarz's patch plus some ReST/Sphinx tweaks

  • new file docs/topics/db/examples/index.txt

    diff --git a/docs/topics/db/examples/index.txt b/docs/topics/db/examples/index.txt
    new file mode 100644
    - +  
     1========================================
     2Examples of model relationship API usage
     3========================================
     4
     5.. toctree::
     6   :maxdepth: 1
     7
     8   many_to_many
     9   many_to_one
     10   one_to_one
  • new file docs/topics/db/examples/many_to_many.txt

    diff --git a/docs/topics/db/examples/many_to_many.txt b/docs/topics/db/examples/many_to_many.txt
    new file mode 100644
    - +  
     1##########################
     2Many-to-many relationships
     3##########################
     4
     5.. highlight:: pycon
     6
     7To define a many-to-many relationship, use :ref:`ref-manytomany`.
     8
     9In this example, an ``Article`` can be published in multiple ``Publication``
     10objects, and a ``Publication`` has multiple ``Article`` objects:
     11
     12.. code-block:: python
     13
     14    from django.db import models
     15
     16    class Publication(models.Model):
     17        title = models.CharField(max_length=30)
     18
     19        def __unicode__(self):
     20            return self.title
     21
     22        class Meta:
     23            ordering = ('title',)
     24
     25    class Article(models.Model):
     26        headline = models.CharField(max_length=100)
     27        publications = models.ManyToManyField(Publication)
     28
     29        def __unicode__(self):
     30            return self.headline
     31
     32        class Meta:
     33            ordering = ('headline',)
     34
     35What follows are examples of operations that can be performed using the Python
     36API facilities.
     37
     38Create a couple of Publications::
     39
     40    >>> p1 = Publication(title='The Python Journal')
     41    >>> p1.save()
     42    >>> p2 = Publication(title='Science News')
     43    >>> p2.save()
     44    >>> p3 = Publication(title='Science Weekly')
     45    >>> p3.save()
     46
     47Create an Article::
     48
     49    >>> a1 = Article(headline='Django lets you build Web apps easily')
     50
     51You can't associate it with a Publication until it's been saved::
     52
     53    >>> a1.publications.add(p1)
     54    Traceback (most recent call last):
     55    ...
     56    ValueError: 'Article' instance needs to have a primary key value before a many-to-many relationship can be used.
     57
     58Save it!
     59::
     60
     61    >>> a1.save()
     62
     63Associate the Article with a Publication::
     64
     65    >>> a1.publications.add(p1)
     66
     67Create another Article, and set it to appear in both Publications::
     68
     69    >>> a2 = Article(headline='NASA uses Python')
     70    >>> a2.save()
     71    >>> a2.publications.add(p1, p2)
     72    >>> a2.publications.add(p3)
     73
     74Adding a second time is OK::
     75
     76    >>> a2.publications.add(p3)
     77
     78Adding an object of the wrong type raises TypeError::
     79
     80    >>> a2.publications.add(a1)
     81    Traceback (most recent call last):
     82    ...
     83    TypeError: 'Publication' instance expected
     84
     85Add a Publication directly via publications.add by using keyword arguments::
     86
     87    >>> new_publication = a2.publications.create(title='Highlights for Children')
     88
     89Article objects have access to their related Publication objects::
     90
     91    >>> a1.publications.all()
     92    [<Publication: The Python Journal>]
     93    >>> a2.publications.all()
     94    [<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>, <Publication: The Python Journal>]
     95
     96Publication objects have access to their related Article objects::
     97
     98    >>> p2.article_set.all()
     99    [<Article: NASA uses Python>]
     100    >>> p1.article_set.all()
     101    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     102    >>> Publication.objects.get(id=4).article_set.all()
     103    [<Article: NASA uses Python>]
     104
     105Many-to-many relationships can be queried using :ref:`lookups across relationships <lookups-that-span-relationships>`::
     106
     107    >>> Article.objects.filter(publications__id__exact=1)
     108    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     109    >>> Article.objects.filter(publications__pk=1)
     110    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     111    >>> Article.objects.filter(publications=1)
     112    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     113    >>> Article.objects.filter(publications=p1)
     114    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     115
     116    >>> Article.objects.filter(publications__title__startswith="Science")
     117    [<Article: NASA uses Python>, <Article: NASA uses Python>]
     118
     119    >>> Article.objects.filter(publications__title__startswith="Science").distinct()
     120    [<Article: NASA uses Python>]
     121
     122The count() function respects distinct() as well::
     123
     124    >>> Article.objects.filter(publications__title__startswith="Science").count()
     125    2
     126
     127    >>> Article.objects.filter(publications__title__startswith="Science").distinct().count()
     128    1
     129
     130    >>> Article.objects.filter(publications__in=[1,2]).distinct()
     131    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     132    >>> Article.objects.filter(publications__in=[p1,p2]).distinct()
     133    [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]
     134
     135Reverse m2m queries are supported (i.e., starting at the table that doesn't have
     136a ManyToManyField)::
     137
     138    >>> Publication.objects.filter(id__exact=1)
     139    [<Publication: The Python Journal>]
     140    >>> Publication.objects.filter(pk=1)
     141    [<Publication: The Python Journal>]
     142
     143    >>> Publication.objects.filter(article__headline__startswith="NASA")
     144    [<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>, <Publication: The Python Journal>]
     145
     146    >>> Publication.objects.filter(article__id__exact=1)
     147    [<Publication: The Python Journal>]
     148    >>> Publication.objects.filter(article__pk=1)
     149    [<Publication: The Python Journal>]
     150    >>> Publication.objects.filter(article=1)
     151    [<Publication: The Python Journal>]
     152    >>> Publication.objects.filter(article=a1)
     153    [<Publication: The Python Journal>]
     154
     155    >>> Publication.objects.filter(article__in=[1,2]).distinct()
     156    [<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>, <Publication: The Python Journal>]
     157    >>> Publication.objects.filter(article__in=[a1,a2]).distinct()
     158    [<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>, <Publication: The Python Journal>]
     159
     160Excluding a related item works as you would expect, too (although the SQL
     161involved is a little complex)::
     162
     163    >>> Article.objects.exclude(publications=p2)
     164    [<Article: Django lets you build Web apps easily>]
     165
     166If we delete a Publication, its Articles won't be able to access it::
     167
     168    >>> p1.delete()
     169    >>> Publication.objects.all()
     170    [<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>]
     171    >>> a1 = Article.objects.get(pk=1)
     172    >>> a1.publications.all()
     173    []
     174
     175If we delete an Article, its Publications won't be able to access it::
     176
     177    >>> a2.delete()
     178    >>> Article.objects.all()
     179    [<Article: Django lets you build Web apps easily>]
     180    >>> p2.article_set.all()
     181    []
     182
     183Adding via the 'other' end of an m2m::
     184
     185    >>> a4 = Article(headline='NASA finds intelligent life on Earth')
     186    >>> a4.save()
     187    >>> p2.article_set.add(a4)
     188    >>> p2.article_set.all()
     189    [<Article: NASA finds intelligent life on Earth>]
     190    >>> a4.publications.all()
     191    [<Publication: Science News>]
     192
     193Adding via the other end using keywords::
     194
     195    >>> new_article = p2.article_set.create(headline='Oxygen-free diet works wonders')
     196    >>> p2.article_set.all()
     197    [<Article: NASA finds intelligent life on Earth>, <Article: Oxygen-free diet works wonders>]
     198    >>> a5 = p2.article_set.all()[1]
     199    >>> a5.publications.all()
     200    [<Publication: Science News>]
     201
     202Removing publication from an article::
     203
     204    >>> a4.publications.remove(p2)
     205    >>> p2.article_set.all()
     206    [<Article: Oxygen-free diet works wonders>]
     207    >>> a4.publications.all()
     208    []
     209
     210And from the other end::
     211
     212    >>> p2.article_set.remove(a5)
     213    >>> p2.article_set.all()
     214    []
     215    >>> a5.publications.all()
     216    []
     217
     218Relation sets can be assigned. Assignment clears any existing set members::
     219
     220    >>> a4.publications.all()
     221    [<Publication: Science News>]
     222    >>> a4.publications = [p3]
     223    >>> a4.publications.all()
     224    [<Publication: Science Weekly>]
     225
     226Relation sets can be cleared::
     227
     228    >>> p2.article_set.clear()
     229    >>> p2.article_set.all()
     230    []
     231
     232And you can clear from the other end::
     233
     234    >>> p2.article_set.add(a4, a5)
     235    >>> p2.article_set.all()
     236    [<Article: NASA finds intelligent life on Earth>, <Article: Oxygen-free diet works wonders>]
     237    >>> a4.publications.all()
     238    [<Publication: Science News>, <Publication: Science Weekly>]
     239    >>> a4.publications.clear()
     240    >>> a4.publications.all()
     241    []
     242    >>> p2.article_set.all()
     243    [<Article: Oxygen-free diet works wonders>]
     244
     245Recreate the article and Publication we have deleted::
     246
     247    >>> p1 = Publication(title='The Python Journal')
     248    >>> p1.save()
     249    >>> a2 = Article(headline='NASA uses Python')
     250    >>> a2.save()
     251    >>> a2.publications.add(p1, p2, p3)
     252
     253Bulk delete some Publications - references to deleted publications should go::
     254
     255    >>> Publication.objects.filter(title__startswith='Science').delete()
     256    >>> Publication.objects.all()
     257    [<Publication: Highlights for Children>, <Publication: The Python Journal>]
     258    >>> Article.objects.all()
     259    [<Article: Django lets you build Web apps easily>, <Article: NASA finds intelligent life on Earth>, <Article: NASA uses Python>, <Article: Oxygen-free diet works wonders>]
     260    >>> a2.publications.all()
     261    [<Publication: The Python Journal>]
     262
     263Bulk delete some articles - references to deleted objects should go::
     264
     265    >>> q = Article.objects.filter(headline__startswith='Django')
     266    >>> print q
     267    [<Article: Django lets you build Web apps easily>]
     268    >>> q.delete()
     269
     270After the delete, the QuerySet cache needs to be cleared, and the referenced
     271objects should be gone::
     272
     273    >>> print q
     274    []
     275    >>> p1.article_set.all()
     276    [<Article: NASA uses Python>]
     277
     278An alternate to calling clear() is to assign the empty set::
     279
     280    >>> p1.article_set = []
     281    >>> p1.article_set.all()
     282    []
     283
     284    >>> a2.publications = [p1, new_publication]
     285    >>> a2.publications.all()
     286    [<Publication: Highlights for Children>, <Publication: The Python Journal>]
     287    >>> a2.publications = []
     288    >>> a2.publications.all()
     289    []
  • new file docs/topics/db/examples/many_to_one.txt

    diff --git a/docs/topics/db/examples/many_to_one.txt b/docs/topics/db/examples/many_to_one.txt
    new file mode 100644
    - +  
     1#########################
     2Many-to-one relationships
     3#########################
     4
     5.. highlight:: pycon
     6
     7To define a many-to-one relationship, use :class:`~django.db.models.ForeignKey`.
     8
     9.. code-block:: python
     10
     11    from django.db import models
     12
     13    class Reporter(models.Model):
     14        first_name = models.CharField(max_length=30)
     15        last_name = models.CharField(max_length=30)
     16        email = models.EmailField()
     17
     18        def __unicode__(self):
     19            return u"%s %s" % (self.first_name, self.last_name)
     20
     21    class Article(models.Model):
     22        headline = models.CharField(max_length=100)
     23        pub_date = models.DateField()
     24        reporter = models.ForeignKey(Reporter)
     25
     26        def __unicode__(self):
     27            return self.headline
     28
     29        class Meta:
     30            ordering = ('headline',)
     31
     32What follows are examples of operations that can be performed using the Python
     33API facilities.
     34
     35Create a few Reporters::
     36
     37    >>> r = Reporter(first_name='John', last_name='Smith', email='john@example.com')
     38    >>> r.save()
     39
     40    >>> r2 = Reporter(first_name='Paul', last_name='Jones', email='paul@example.com')
     41    >>> r2.save()
     42
     43Create an Article::
     44
     45    >>> from datetime import datetime
     46    >>> a = Article(id=None, headline="This is a test", pub_date=datetime(2005, 7, 27), reporter=r)
     47    >>> a.save()
     48
     49    >>> a.reporter.id
     50    1
     51
     52    >>> a.reporter
     53    <Reporter: John Smith>
     54
     55Article objects have access to their related Reporter objects::
     56
     57    >>> r = a.reporter
     58
     59These are strings instead of unicode strings because that's what was used in
     60the creation of this reporter (and we haven't refreshed the data from the
     61database, which always returns unicode strings)::
     62
     63    >>> r.first_name, r.last_name
     64    ('John', 'Smith')
     65
     66Create an Article via the Reporter object::
     67
     68    >>> new_article = r.article_set.create(headline="John's second story", pub_date=datetime(2005, 7, 29))
     69    >>> new_article
     70    <Article: John's second story>
     71    >>> new_article.reporter
     72    <Reporter: John Smith>
     73    >>> new_article.reporter.id
     74    1
     75
     76Create a new article, and add it to the article set::
     77
     78    >>> new_article2 = Article(headline="Paul's story", pub_date=datetime(2006, 1, 17))
     79    >>> r.article_set.add(new_article2)
     80    >>> new_article2.reporter
     81    <Reporter: John Smith>
     82    >>> new_article2.reporter.id
     83    1
     84    >>> r.article_set.all()
     85    [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]
     86
     87Add the same article to a different article set - check that it moves::
     88
     89    >>> r2.article_set.add(new_article2)
     90    >>> new_article2.reporter.id
     91    2
     92    >>> new_article2.reporter
     93    <Reporter: Paul Jones>
     94
     95Adding an object of the wrong type raises TypeError::
     96
     97    >>> r.article_set.add(r2)
     98    Traceback (most recent call last):
     99    ...
     100    TypeError: 'Article' instance expected
     101
     102    >>> r.article_set.all()
     103    [<Article: John's second story>, <Article: This is a test>]
     104    >>> r2.article_set.all()
     105    [<Article: Paul's story>]
     106
     107    >>> r.article_set.count()
     108    2
     109
     110    >>> r2.article_set.count()
     111    1
     112
     113Note that in the last example the article has moved from John to Paul.
     114
     115Related managers support field lookups as well.
     116The API automatically follows relationships as far as you need.
     117Use double underscores to separate relationships.
     118This works as many levels deep as you want. There's no limit. For example::
     119
     120    >>> r.article_set.filter(headline__startswith='This')
     121    [<Article: This is a test>]
     122
     123    # Find all Articles for any Reporter whose first name is "John".
     124    >>> Article.objects.filter(reporter__first_name__exact='John')
     125    [<Article: John's second story>, <Article: This is a test>]
     126
     127Exact match is implied here::
     128
     129    >>> Article.objects.filter(reporter__first_name='John')
     130    [<Article: John's second story>, <Article: This is a test>]
     131
     132Query twice over the related field. This translates to an AND condition in the
     133WHERE clause::
     134
     135    >>> Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith')
     136    [<Article: John's second story>, <Article: This is a test>]
     137
     138For the related lookup you can supply a primary key value or pass the related
     139object explicitly::
     140
     141    >>> Article.objects.filter(reporter__pk=1)
     142    [<Article: John's second story>, <Article: This is a test>]
     143    >>> Article.objects.filter(reporter=1)
     144    [<Article: John's second story>, <Article: This is a test>]
     145    >>> Article.objects.filter(reporter=r)
     146    [<Article: John's second story>, <Article: This is a test>]
     147
     148    >>> Article.objects.filter(reporter__in=[1,2]).distinct()
     149    [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]
     150    >>> Article.objects.filter(reporter__in=[r,r2]).distinct()
     151    [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]
     152
     153You can also use a queryset instead of a literal list of instances::
     154
     155    >>> Article.objects.filter(reporter__in=Reporter.objects.filter(first_name='John')).distinct()
     156    [<Article: John's second story>, <Article: This is a test>]
     157
     158Querying in the opposite direction::
     159
     160    >>> Reporter.objects.filter(article__pk=1)
     161    [<Reporter: John Smith>]
     162    >>> Reporter.objects.filter(article=1)
     163    [<Reporter: John Smith>]
     164    >>> Reporter.objects.filter(article=a)
     165    [<Reporter: John Smith>]
     166
     167    >>> Reporter.objects.filter(article__headline__startswith='This')
     168    [<Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>]
     169    >>> Reporter.objects.filter(article__headline__startswith='This').distinct()
     170    [<Reporter: John Smith>]
     171
     172Counting in the opposite direction works in conjunction with distinct()::
     173
     174    >>> Reporter.objects.filter(article__headline__startswith='This').count()
     175    3
     176    >>> Reporter.objects.filter(article__headline__startswith='This').distinct().count()
     177    1
     178
     179Queries can go round in circles::
     180
     181    >>> Reporter.objects.filter(article__reporter__first_name__startswith='John')
     182    [<Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>]
     183    >>> Reporter.objects.filter(article__reporter__first_name__startswith='John').distinct()
     184    [<Reporter: John Smith>]
     185    >>> Reporter.objects.filter(article__reporter__exact=r).distinct()
     186    [<Reporter: John Smith>]
     187
     188If you delete a reporter, his articles will be deleted (assuming that the
     189ForeignKey was defined with :attr:`django.db.models.ForeignKey.on_delete` set to
     190``CASCADE``, which is the default)::
     191
     192    >>> Article.objects.all()
     193    [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]
     194    >>> Reporter.objects.order_by('first_name')
     195    [<Reporter: John Smith>, <Reporter: Paul Jones>]
     196    >>> r2.delete()
     197    >>> Article.objects.all()
     198    [<Article: John's second story>, <Article: This is a test>]
     199    >>> Reporter.objects.order_by('first_name')
     200    [<Reporter: John Smith>]
     201
     202You can delete using a JOIN in the query::
     203
     204    >>> Reporter.objects.filter(article__headline__startswith='This').delete()
     205    >>> Reporter.objects.all()
     206    []
     207    >>> Article.objects.all()
     208    []
  • new file docs/topics/db/examples/one_to_one.txt

    diff --git a/docs/topics/db/examples/one_to_one.txt b/docs/topics/db/examples/one_to_one.txt
    new file mode 100644
    - +  
     1########################
     2One-to-one relationships
     3########################
     4
     5.. highlight:: pycon
     6
     7To define a one-to-one relationship, use :ref:`ref-onetoone`.
     8
     9In this example, a ``Place`` optionally can be a ``Restaurant``:
     10
     11.. code-block:: python
     12
     13    from django.db import models, transaction, IntegrityError
     14
     15    class Place(models.Model):
     16        name = models.CharField(max_length=50)
     17        address = models.CharField(max_length=80)
     18
     19        def __unicode__(self):
     20            return u"%s the place" % self.name
     21
     22    class Restaurant(models.Model):
     23        place = models.OneToOneField(Place, primary_key=True)
     24        serves_hot_dogs = models.BooleanField()
     25        serves_pizza = models.BooleanField()
     26
     27        def __unicode__(self):
     28            return u"%s the restaurant" % self.place.name
     29
     30    class Waiter(models.Model):
     31        restaurant = models.ForeignKey(Restaurant)
     32        name = models.CharField(max_length=50)
     33
     34        def __unicode__(self):
     35            return u"%s the waiter at %s" % (self.name, self.restaurant)
     36
     37What follows are examples of operations that can be performed using the Python
     38API facilities.
     39
     40Create a couple of Places::
     41
     42    >>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
     43    >>> p1.save()
     44    >>> p2 = Place(name='Ace Hardware', address='1013 N. Ashland')
     45    >>> p2.save()
     46
     47Create a Restaurant. Pass the ID of the "parent" object as this object's ID::
     48
     49    >>> r = Restaurant(place=p1, serves_hot_dogs=True, serves_pizza=False)
     50    >>> r.save()
     51
     52A Restaurant can access its place::
     53
     54    >>> r.place
     55    <Place: Demon Dogs the place>
     56
     57A Place can access its restaurant, if available::
     58
     59    >>> p1.restaurant
     60    <Restaurant: Demon Dogs the restaurant>
     61
     62p2 doesn't have an associated restaurant::
     63
     64    >>> p2.restaurant
     65    Traceback (most recent call last):
     66        ...
     67    DoesNotExist: Restaurant matching query does not exist.
     68
     69Set the place using assignment notation. Because place is the primary key on
     70Restaurant, the save will create a new restaurant::
     71
     72    >>> r.place = p2
     73    >>> r.save()
     74    >>> p2.restaurant
     75    <Restaurant: Ace Hardware the restaurant>
     76    >>> r.place
     77    <Place: Ace Hardware the place>
     78
     79Set the place back again, using assignment in the reverse direction::
     80
     81    >>> p1.restaurant = r
     82    >>> p1.restaurant
     83    <Restaurant: Demon Dogs the restaurant>
     84
     85Restaurant.objects.all() just returns the Restaurants, not the Places.  Note
     86that there are two restaurants - Ace Hardware the Restaurant was created in the
     87call to r.place = p2::
     88
     89    >>> Restaurant.objects.all()
     90    [<Restaurant: Demon Dogs the restaurant>, <Restaurant: Ace Hardware the restaurant>]
     91
     92Place.objects.all() returns all Places, regardless of whether they have
     93Restaurants::
     94
     95    >>> Place.objects.order_by('name')
     96    [<Place: Ace Hardware the place>, <Place: Demon Dogs the place>]
     97
     98You can query the models using :ref:`lookups across relationships <lookups-that-span-relationships>`::
     99
     100    >>> Restaurant.objects.get(place=p1)
     101    <Restaurant: Demon Dogs the restaurant>
     102    >>> Restaurant.objects.get(place__pk=1)
     103    <Restaurant: Demon Dogs the restaurant>
     104    >>> Restaurant.objects.filter(place__name__startswith="Demon")
     105    [<Restaurant: Demon Dogs the restaurant>]
     106    >>> Restaurant.objects.exclude(place__address__contains="Ashland")
     107    [<Restaurant: Demon Dogs the restaurant>]
     108
     109This of course works in reverse::
     110
     111    >>> Place.objects.get(pk=1)
     112    <Place: Demon Dogs the place>
     113    >>> Place.objects.get(restaurant__place__exact=p1)
     114    <Place: Demon Dogs the place>
     115    >>> Place.objects.get(restaurant=r)
     116    <Place: Demon Dogs the place>
     117    >>> Place.objects.get(restaurant__place__name__startswith="Demon")
     118    <Place: Demon Dogs the place>
     119
     120Add a Waiter to the Restaurant::
     121
     122    >>> w = r.waiter_set.create(name='Joe')
     123    >>> w.save()
     124    >>> w
     125    <Waiter: Joe the waiter at Demon Dogs the restaurant>
     126
     127Query the waiters::
     128
     129    >>> Waiter.objects.filter(restaurant__place=p1)
     130    [<Waiter: Joe the waiter at Demon Dogs the restaurant>]
     131    >>> Waiter.objects.filter(restaurant__place__name__startswith="Demon")
     132    [<Waiter: Joe the waiter at Demon Dogs the restaurant>]
  • docs/topics/db/index.txt

    diff --git a/docs/topics/db/index.txt b/docs/topics/db/index.txt
    a b  
    1919   multi-db
    2020   tablespaces
    2121   optimization
     22   examples/index
  • docs/topics/db/models.txt

    diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
    a b  
    1818* With all of this, Django gives you an automatically-generated
    1919  database-access API; see :doc:`/topics/db/queries`.
    2020
    21 .. seealso::
    22 
    23     A companion to this document is the `official repository of model
    24     examples`_. (In the Django source distribution, these examples are in the
    25     ``tests/modeltests`` directory.)
    26 
    27     .. _official repository of model examples: http://code.djangoproject.com/browser/django/trunk/tests/modeltests
    28 
    2921Quick example
    3022=============
    3123
     
    326318    For details on accessing backwards-related objects, see the
    327319    :ref:`Following relationships backward example <backwards-related-objects>`.
    328320
    329     For sample code, see the `Many-to-one relationship model tests`_.
    330 
    331     .. _Many-to-one relationship model tests: http://code.djangoproject.com/browser/django/trunk/tests/modeltests/many_to_one
     321    For sample code, see the :doc:`Many-to-one relationship model tests
     322    </topics/db/examples/many_to_one>`.
    332323
    333324Many-to-many relationships
    334325~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    376367
    377368.. seealso::
    378369
    379     See the `Many-to-many relationship model example`_ for a full example.
    380 
    381 .. _Many-to-many relationship model example: http://code.djangoproject.com/browser/django/trunk/tests/modeltests/many_to_many/models.py
     370    See the :doc:`Many-to-many relationship model example
     371    </topics/db/examples/many_to_many>` for a full example.
    382372
    383373:class:`~django.db.models.ManyToManyField` fields also accept a number of extra
    384374arguments which are explained in :ref:`the model field reference
     
    569559
    570560.. seealso::
    571561
    572     See the `One-to-one relationship model example`_ for a full example.
    573 
    574 .. _One-to-one relationship model example: http://code.djangoproject.com/browser/django/trunk/tests/modeltests/one_to_one/models.py
     562    See the :doc:`One-to-one relationship model example
     563    </topics/db/examples/one_to_one>` for a full example.
    575564
    576565:class:`~django.db.models.OneToOneField` fields also accept one optional argument
    577566described in the :ref:`model field reference <ref-onetoone>`.
  • docs/topics/db/queries.txt

    diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
    a b  
    483483Again, this only scratches the surface. A complete reference can be found in the
    484484:ref:`field lookup reference <field-lookups>`.
    485485
     486.. _lookups-that-span-relationships:
     487
    486488Lookups that span relationships
    487489-------------------------------
    488490
Back to Top