Brian, I think the solution is to add a GenericRelation to your entries model; see http://www.djangoproject.com/documentation/contenttypes/#reverse-generic-relationsfor an explanation. I think that after doing this you'll be able to access p.comments.count (assuming that the generic relation is named "comments"). I haven't used the contenttypes framework yet, but from the looks of it I believe that will work.
-- Scott On Fri, Jul 18, 2008 at 12:21 PM, brianmac44 <[EMAIL PROTECTED]> wrote: > > Hi Scott, > Thanks for your help, but I'm still having trouble. > I using django-threadedcomments > http://code.google.com/p/django-threadedcomments/ > so its a little confusing. > > Here are my models > http://dpaste.com/65848/ > > -Brian > > On Jul 18, 12:01 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote: > > Brian, without knowing exactly how your models are configured, you can do > > something like this: > > > > {{ p.comment_set.count }} > > > > If you use it in more than one place (e.g., as {% if p.comment_set.count > %} > > ... {{ p.comment_set.count }} ...), you will want to optimize things so > that > > the SQL "COUNT()" query is executed only once: > > > > {% with p.comment_set.count as comment_count %} > > {% if comment_count %} . . . {{ comment_count }} . . . {% endif %} > > {% endwith %} > > > > If you have any trouble getting this working, please let us have a look > at > > your entry and comment models (use dpaste.com) and we can help you > figure > > out exactly what to write. > > > > -- Scott > > > > > > > > On Fri, Jul 18, 2008 at 11:47 AM, brianmac44 <[EMAIL PROTECTED]> wrote: > > > > > I have two tables, one is entries and the other is comments. > > > > > In the template I would like display how many comments for each entry > > > and some other entry data. > > > So far I have... > > > > > view: > > > entries_list = entries.objects.filter( ...) > > > > > template: > > > {% for p in object_list %} > > > <tr> > > > <td> > > > {{ p.name }} > > > </td> > > > <td> > > > ... > > > </td> > > > </tr> > > > {% endfor %} > > > > > How is this done? Should I use select_related in the view? > > > Thanks in advance. > > > > --http://scott.andstuff.org/|http://truthadorned.org/<http://scott.andstuff.org/%7Chttp://truthadorned.org/> > > > -- http://scott.andstuff.org/ | http://truthadorned.org/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---