Re: More efficient m2m assignment SQL

2012-09-20 Thread Anssi Kääriäinen
On 27 heinä, 18:50, Jeremy Dunck wrote: > Ah, yes, hmm.  Actually, it *is* possible to get signals attached to > the through. > > from django.db.models import signals > signals.pre_delete.connect(handler, sender=Voter.districts.through) > > So I don't think we can even take that shortcut on just t

Re: More efficient m2m assignment SQL

2012-07-27 Thread Jeremy Dunck
On Thu, Jul 26, 2012 at 11:26 PM, Anssi Kääriäinen wrote: > On 27 heinä, 08:15, Jeremy Dunck wrote: ... >> I would have expected something along the lines of : >> >> DELETE FROM `api_voter_districts` WHERE `voter_id` = 1 >> >> But instead it's 2 queries: >> >> SELECT `api_voter_districts`.`id`, `

Re: More efficient m2m assignment SQL

2012-07-26 Thread Anssi Kääriäinen
On 27 heinä, 08:15, Jeremy Dunck wrote: > I have 2 models: > > class District(Model): >   pass > > class Voter(Model): >    districts = ManyToManyField(District) > > Sometimes I want to reset the m2m list: > > voter.districts = other_districts > > I noticed that this uses ManyRelatedManager._clear

More efficient m2m assignment SQL

2012-07-26 Thread Jeremy Dunck
I have 2 models: class District(Model): pass class Voter(Model): districts = ManyToManyField(District) Sometimes I want to reset the m2m list: voter.districts = other_districts I noticed that this uses ManyRelatedManager._clear_items, which, among other things, boils down to: voter.distr