Re: Counting over a ManyToManyField of a ManyToManyField, a question of style.

2008-03-27 Thread [EMAIL PROTECTED]
Yes, instead of returning all the records and counting them in python you would be using your databases COUNT() funciton. On Mar 27, 10:33 pm, Rodrigo Culagovski <[EMAIL PROTECTED]> wrote: > On Mar 27, 3:43 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > Well, books can be redefined as

Re: Counting over a ManyToManyField of a ManyToManyField, a question of style.

2008-03-27 Thread Rodrigo Culagovski
On Mar 27, 3:43 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Well, books can be redefined as: > > def books(self): > progs = self.programs.all() > return sum([prog.publications.all().filter(type=u'Book').count() > for prog in progs]) > > and likewise for the other methods. Nice.

Re: Counting over a ManyToManyField of a ManyToManyField, a question of style.

2008-03-27 Thread [EMAIL PROTECTED]
Well, books can be redefined as: def books(self): progs = self.programs.all() return sum([prog.publications.all().filter(type=u'Book').count() for prog in progs]) and likewise for the other methods. On Mar 27, 1:27 pm, Rodrigo Culagovski <[EMAIL PROTECTED]> wrote: > My application has t

Counting over a ManyToManyField of a ManyToManyField, a question of style.

2008-03-27 Thread Rodrigo Culagovski
My application has the following models: Researcher, Program and Publication. Each Researcher has 0 or more Programs as a ManyToManyField, and each Program has 0 or more Publications also as a ManyToManyField. Publication has a 'type' attribute which is a CharField, and has choices: Book, Article