diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2011-08-26 04:34:40 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2011-08-26 04:34:40 +0000 |
| commit | 804a6db86e8b1c129429291da4aebbd797c77ddb (patch) | |
| tree | 176e591788e493d59b9d3a82f913d0d6796775e9 /docs | |
| parent | 5eeb2d56d50dc7b280cd11267add8cf2da5f26a3 (diff) | |
Added a bit to 'Saving ManyToMany Fields' explicitly explaining how to add multiple relations in one statement
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16689 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/db/queries.txt | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index a4267489b9..8e2c0cc021 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -113,6 +113,15 @@ method on the field to add a record to the relation. This example adds the >>> joe = Author.objects.create(name="Joe") >>> entry.authors.add(joe) +To add multiple records to a ``ManyToManyField`` in one go, include multiple +arguments in the call to ``add()``, like this:: + + >>> john = Author.objects.create(name="John") + >>> paul = Author.objects.create(name="Paul") + >>> george = Author.objects.create(name="George") + >>> ringo = Author.objects.create(name="Ringo") + >>> entry.authors.add(john, paul, george, ringo) + Django will complain if you try to assign or add an object of the wrong type. Retrieving objects |
