Ticket #5390: related.diff
File related.diff, 2.7 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._get_pk_val() in new_ids) or obj in new_ids] 351 dispatcher.send(signal=signals.m2m_add_items, sender=self.model, instance=self.instance, objs=added_objs) 352 346 353 transaction.commit_unless_managed() 347 354 348 355 def _remove_items(self, source_col_name, target_col_name, *objs): … … 365 372 (self.join_table, source_col_name, 366 373 target_col_name, ",".join(['%s'] * len(old_ids))), 367 374 [self._pk_val] + list(old_ids)) 375 dispatcher.send(signal=signals.m2m_remove_items, sender=self.model, instance=self.instance, objs=objs) 368 376 transaction.commit_unless_managed() 369 377 370 378 def _clear_items(self, source_col_name): 371 379 # source_col_name: the PK colname in join_table for the source object 380 dispatcher.send(signal=signals.m2m_clear_items, sender=self.model, instance=self.instance) 372 381 cursor = connection.cursor() 373 382 cursor.execute("DELETE FROM %s WHERE %s = %%s" % \ 374 383 (self.join_table, source_col_name),