On Fri, 2009-04-10 at 18:15 -0700, chris wrote: > > > On Apr 10, 6:55 pm, Malcolm Tredinnick <malc...@pointy-stick.com> > wrote: > > > However there could be, and likely are, many TextChar objects with the > > same edition value, so it would be ambiguous as to which particular > > object to return. Since there's no natural choice, there's no API to ask > > Django to guess or provide a sample object or anything like that. It's > > not appropriate to return a model object for that type of query. > > > > What is the real problem you are trying to solve here? Why do you need > > an object back? > > Well, I want to display in a template the name of the edition, rather > than the primary key, which means nothing to the user. Meanwhile I > resorted to do the footwork in the view function like so, which allows > me to achieve what I need: > > reslist = [{'edition' :Edition.objects.get(pk=a['edition']).__unicode__ > (), 'count': a['char__count']} for a in char.textchar_set.values > ('edition').annotate(Count('char'))]
Aah .. I'm dumb. I misread your original question as asking for a TextChar object back (since you were querying on the TextChar model). Returning Edition models -- which is indeed what you were asking for and since completing my remedial reading course I can now see that -- is definitely possible. Use Edition as the root for the queryset (the model to query). This does what you're after: Edition.objects.filter(textchar__unichar=char).annotate(Count("textchar")) That will return a bunch of Edition objects, each with a textchar__count attribute. Sorry for being so dense early on. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---