mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
magic-removal: Fixed #1143 -- Fixed backwards incompatibilities in many-to-many DB API lookups, added support for reverse many-to-many lookups, added unit tests. Thanks, Russ
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1802 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -28,6 +28,8 @@ API_TESTS = """
|
||||
>>> p1.save()
|
||||
>>> p2 = Publication(id=None, title='Science News')
|
||||
>>> p2.save()
|
||||
>>> p3 = Publication(id=None, title='Science Weekly')
|
||||
>>> p3.save()
|
||||
|
||||
# Create an Article.
|
||||
>>> a1 = Article(id=None, headline='Django lets you build Web apps easily')
|
||||
@@ -50,14 +52,14 @@ False
|
||||
True
|
||||
>>> a2.set_publications([p1.id])
|
||||
True
|
||||
>>> a2.set_publications([p1.id, p2.id])
|
||||
>>> a2.set_publications([p1.id, p2.id, p3.id])
|
||||
True
|
||||
|
||||
# Article objects have access to their related Publication objects.
|
||||
>>> a1.get_publication_list()
|
||||
[The Python Journal]
|
||||
>>> a2.get_publication_list()
|
||||
[The Python Journal, Science News]
|
||||
[The Python Journal, Science News, Science Weekly]
|
||||
|
||||
# Publication objects have access to their related Article objects.
|
||||
>>> p2.get_article_list()
|
||||
@@ -65,10 +67,27 @@ True
|
||||
>>> p1.get_article_list(order_by=['headline'])
|
||||
[Django lets you build Web apps easily, NASA uses Python]
|
||||
|
||||
# We can perform kwarg queries across m2m relationships
|
||||
>>> Article.objects.get_list(publications__pk=1)
|
||||
[Django lets you build Web apps easily, NASA uses Python]
|
||||
|
||||
>>> Article.objects.get_list(publications__title__startswith="Science")
|
||||
[NASA uses Python, NASA uses Python]
|
||||
|
||||
>>> Article.objects.get_list(publications__title__startswith="Science", distinct=True)
|
||||
[NASA uses Python]
|
||||
|
||||
# Reverse m2m queries (i.e., start at the table that doesn't have a ManyToManyField)
|
||||
>>> Publication.objects.get_list(articles__headline__startswith="NASA")
|
||||
[The Python Journal, Science News, Science Weekly]
|
||||
|
||||
>>> Publication.objects.get_list(articles__pk=1)
|
||||
[The Python Journal]
|
||||
|
||||
# If we delete a Publication, its Articles won't be able to access it.
|
||||
>>> p1.delete()
|
||||
>>> Publication.objects.get_list()
|
||||
[Science News]
|
||||
[Science News, Science Weekly]
|
||||
>>> a1 = Article.objects.get_object(pk=1)
|
||||
>>> a1.get_publication_list()
|
||||
[]
|
||||
|
||||
@@ -66,6 +66,8 @@ DoesNotExist: Restaurant does not exist for {'place__id__exact': ...}
|
||||
|
||||
>>> Restaurant.objects.get_object(place__id__exact=1)
|
||||
Demon Dogs the restaurant
|
||||
>>> Restaurant.objects.get_object(place__name__startswith="Demon")
|
||||
Demon Dogs the restaurant
|
||||
>>> Restaurant.objects.get_object(pk=1)
|
||||
Demon Dogs the restaurant
|
||||
|
||||
|
||||
Reference in New Issue
Block a user