Code

Ticket #3142: faster_m2m_assignment.diff

File faster_m2m_assignment.diff, 781 bytes (added by mitakummaa@…, 7 years ago)

Patch against trunk r4201

Line 
1Index: django/db/models/fields/related.py
2===================================================================
3--- django/db/models/fields/related.py  (revision 4201)
4+++ django/db/models/fields/related.py  (working copy)
5@@ -405,8 +405,7 @@
6 
7         manager = self.__get__(instance)
8         manager.clear()
9-        for obj in value:
10-            manager.add(obj)
11+        manager.add(*value)
12 
13 class ReverseManyRelatedObjectsDescriptor(object):
14     # This class provides the functionality that makes the related-object
15@@ -447,8 +446,7 @@
16 
17         manager = self.__get__(instance)
18         manager.clear()
19-        for obj in value:
20-            manager.add(obj)
21+        manager.add(*value)
22 
23 class ForeignKey(RelatedField, Field):
24     empty_strings_allowed = False