lol... i have answered to late ... it seems that after all i have said the same thing as Tiago
Regards On Mon, Sep 14, 2009 at 11:58 PM, Alexandru-Emil Lupu <gang.al...@gmail.com>wrote: > i do not know if is database killing or not, but you could try some of > those > > Person.objects.select_related(depth=2).get() > > > or you could make something like > > Membership.objects.select_related(depth=1).get() > > That will perform a query on the entire membership table and related tables > in order to extract the values > but you could try something like > > Membership.objects.distinct('person_id').select_related(depth=1).get() > > > Alecs > > > > > On Mon, Sep 14, 2009 at 11:27 PM, W.P. McNeill <bill...@gmail.com> wrote: > >> >> Never mind. Tiago Serafim's reply answered my question for me. >> >> Follow on question: say I want to make a 2-dimensional table of the >> dates when people joined bands. I'd have code that looks like this. >> >> for p in Person.objects.all(): >> for g in Group.objects.all(): >> date = Membership.objects.get(person=p, group=g).join_date >> ... >> >> Am I making (person x group) database calls here? This is impression >> I get from reading: >> >> http://docs.djangoproject.com/en/dev/ref/models/querysets/#id1 >> >> Is this inefficient? Is there a way to do this with a single database >> call? >> >> >> On Sep 14, 11:43 am, "W.P. McNeill" <bill...@gmail.com> wrote: >> > Or maybe another way of asking this, since I don't want to force you >> > to write Python code just to answer my question... >> > >> > If I have the music group model written as shown in the Django >> > documentation is it possible to write a model API statement that gets >> > me this information, or would I have to add fields to the model? >> > >> > Thanks. >> > >> > On Sep 14, 9:46 am, Alexandru-Emil Lupu <gang.al...@gmail.com> wrote: >> > >> > >> > >> > > basically you would have to make a ManyToMany relation thru a class. >> In that >> > > class you make m,n,date field >> > > After that you just use a query to answer the question: Who (Paul)? >> joined >> > > to whom (Beatles), and after that will pop up the ManyToMany date >> field that >> > > will answer to question "when". >> > >> > > I am preety new in django my self .. and i don't know pretty well how >> to do >> > > it... >> > >> > > On Mon, Sep 14, 2009 at 6:21 PM, W.P. McNeill <bill...@gmail.com> >> wrote: >> > >> > > > I can't figure out how to query the values of fields in a ManyToMany >> > > > "through" table. >> > >> > > > For instance, say I'm working with the Beatles database in the >> Django >> > > > documentation ( >> http://docs.djangoproject.com/en/dev/topics/db/models/ >> > > > #extra-fields-on-many-to-many-relationships< >> http://docs.djangoproject.com/en/dev/topics/db/models/%0A#extra-field.. >> .>). >> > > > I want to be able to >> > > > query the date on which Paul joined the Beatles. (As opposed to >> when >> > > > Ringo joined the Beatles, or when Paul joined Wings.) Basically I >> > > > want to treat the Group table as a two-dimensional array, look up: >> > >> > > > Group[Beatles][Paul].date_joined >> > >> > > > and have it return: >> > >> > > > date(1960, 8, 1) >> > >> > > > I'd think this would be easy to do, but I've been playing around >> with >> > > > the command-line database API and I can't figure it out. The >> > > > documentation I've seen describes how to use a Membership field as a >> > > > filter criteria, but not how to look up the actual value. >> > >> > > -- >> > > As programmers create bigger & better idiot proof programs, so the >> universe >> > > creates bigger & better idiots! >> > > I am on web: http://www.alecslupu.ro/ >> > > I am on twitter:http://twitter.com/alecslupu >> > > I am on linkedIn:http://www.linkedin.com/in/alecslupu >> > > Tel: (+4)0748.543.798 >> >> >> > > > -- > As programmers create bigger & better idiot proof programs, so the universe > creates bigger & better idiots! > I am on web: http://www.alecslupu.ro/ > I am on twitter: http://twitter.com/alecslupu > I am on linkedIn: http://www.linkedin.com/in/alecslupu > Tel: (+4)0748.543.798 > > -- As programmers create bigger & better idiot proof programs, so the universe creates bigger & better idiots! I am on web: http://www.alecslupu.ro/ I am on twitter: http://twitter.com/alecslupu I am on linkedIn: http://www.linkedin.com/in/alecslupu Tel: (+4)0748.543.798 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---