Fixed problem with assiging an empty list to m2m related descriptors, introduced in [4231].
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4232 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2d6095ea5e
commit
e859f108f1
|
@ -317,6 +317,8 @@ def create_many_related_manager(superclass):
|
||||||
# *objs - objects to add
|
# *objs - objects to add
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
|
# If there aren't any objects, there is nothing to do.
|
||||||
|
if objs:
|
||||||
# Add the newly created or already existing objects to the join table.
|
# Add the newly created or already existing objects to the join table.
|
||||||
# First find out which items are already added, to avoid adding them twice
|
# First find out which items are already added, to avoid adding them twice
|
||||||
new_ids = set([obj._get_pk_val() for obj in objs])
|
new_ids = set([obj._get_pk_val() for obj in objs])
|
||||||
|
|
|
@ -231,4 +231,16 @@ __test__ = {'API_TESTS':"""
|
||||||
>>> p1.article_set.all()
|
>>> p1.article_set.all()
|
||||||
[<Article: NASA uses Python>]
|
[<Article: NASA uses Python>]
|
||||||
|
|
||||||
|
# An alternate to calling clear() is to assign the empty set
|
||||||
|
>>> p1.article_set = []
|
||||||
|
>>> p1.article_set.all()
|
||||||
|
[]
|
||||||
|
|
||||||
|
>>> a2.publications = [p1, new_publication]
|
||||||
|
>>> a2.publications.all()
|
||||||
|
[<Publication: Highlights for Children>, <Publication: The Python Journal>]
|
||||||
|
>>> a2.publications = []
|
||||||
|
>>> a2.publications.all()
|
||||||
|
[]
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue