Ticket #13022: ticket13022.diff

File ticket13022.diff, 1.4 KB (added by halldor89, 15 years ago)

An attempt at fixing this issue.

  • db/models/fields/related.py

     
    631631            raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name))
    632632
    633633        manager = self.__get__(instance)
    634         manager.clear()
    635         manager.add(*value)
     634        new_pks = set([v.pk for v in value])
     635        old_pks = set([v.pk for v in manager.all()])
     636        tb_added = new_pks-old_pks
     637        tb_removed = old_pks-new_pks
     638        manager.remove(*tb_removed)
     639        manager.add(*tb_added)
    636640
    637641
    638642class ReverseManyRelatedObjectsDescriptor(object):
     
    683687            raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model.  Use %s.%s's Manager instead." % (opts.app_label, opts.object_name))
    684688
    685689        manager = self.__get__(instance)
    686         manager.clear()
    687         manager.add(*value)
     690        new_pks = set([v.pk for v in value])
     691        old_pks = set([v.pk for v in manager.all()])
     692        tb_added = new_pks-old_pks
     693        tb_removed = old_pks-new_pks
     694        manager.remove(*tb_removed)
     695        manager.add(*tb_added)
    688696
    689697class ManyToOneRel(object):
    690698    def __init__(self, to, field_name, related_name=None,
Back to Top