Ticket #5390: related_manager.diff
File related_manager.diff, 2.9 KB (added by , 17 years ago) |
---|
-
db/models/signals.py
10 10 post_delete = object() 11 11 12 12 post_syncdb = object() 13 14 m2m_add_items = object() 15 16 m2m_remove_items = object() 17 18 m2m_clear_items = object() -
db/models/fields/related.py
2 2 from django.db.models import signals, get_model 3 3 from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, get_ul_class 4 4 from django.db.models.related import RelatedObject 5 from django.db.models import signals 6 from django.dispatch import dispatcher 5 7 from django.utils.text import capfirst 6 8 from django.utils.translation import ugettext_lazy, string_concat, ungettext, ugettext as _ 7 9 from django.utils.functional import curry … … 339 341 existing_ids = set([row[0] for row in cursor.fetchall()]) 340 342 341 343 # Add the ones that aren't there already 342 for obj_id in (new_ids - existing_ids): 344 new_ids = new_ids - existing_ids 345 for obj_id in new_ids: 343 346 cursor.execute("INSERT INTO %s (%s, %s) VALUES (%%s, %%s)" % \ 344 347 (self.join_table, source_col_name, target_col_name), 345 348 [self._pk_val, obj_id]) 349 350 added_objs = [obj for obj in objs if (isinstance(obj, self.model) and obj.id in new_ids) or obj in new_ids] 351 dispatcher.send(signal=signals.m2m_add_items, sender=self.model, added=added_objs, 352 source_col_name=source_col_name, target_col_name=target_col_name, instance=self.instance) 353 346 354 transaction.commit_unless_managed() 347 355 348 356 def _remove_items(self, source_col_name, target_col_name, *objs): … … 365 373 (self.join_table, source_col_name, 366 374 target_col_name, ",".join(['%s'] * len(old_ids))), 367 375 [self._pk_val] + list(old_ids)) 376 dispatcher.send(signal=signals.m2m_remove_items, sender=self.model, added=objs, 377 source_col_name=source_col_name, target_col_name=target_col_name, instance=self.instance) 368 378 transaction.commit_unless_managed() 369 379 370 380 def _clear_items(self, source_col_name): … … 373 383 cursor.execute("DELETE FROM %s WHERE %s = %%s" % \ 374 384 (self.join_table, source_col_name), 375 385 [self._pk_val]) 386 dispatcher.send(signal=signals.m2m_clear_items, sender=self.model, 387 source_col_name=source_col_name, instance=self.instance) 376 388 transaction.commit_unless_managed() 377 389 378 390 return ManyRelatedManager