Figured it out. Template wanted (for whatever reason) {% for foo in bar.foos.all %} instead of {% for foo in bar.foos_set.all %}
On Jun 7, 12:09 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I'm just getting more and more stumped. > > I went ahead and created a custom view for Foo, so that's taken care > of, but Bar (which should be easy) isn't working either. > > I have: > class Bar(models.Model): > name= models.CharField(maxlength=100) > foos = models.ManyToManyField(Foo, > filter_interface=models.HORIZONTAL, related_name="foos", null=True, > blank=True) > slug = models.SlugField(prepopulate_from=('name',)) > > In passing it in a generic view, in the template, shouldn't I just be > able to do this? > > {% for foo in bar.foos_set.all %} > test > {% endfor %} > > I get nothing. If I put in {{ bar.foos_set.all }} I get an object > pointer, not a list. > I haven't thrown any errors when I ran syncdb or validate. > > On Jun 7, 8:58 am, "Russell Keith-Magee" <[EMAIL PROTECTED]> > wrote: > > > On 6/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > That's what I thought, too, but I can't seem to access it. Maybe I > > > need to just write a custom view for this page. > > > Based on what you've said so far, you shouldn't need to write a new > > view. You just need to reference the m2m data correctly. Assuming you > > have the models: > > > class Foo(models.Model): > > name = models.CharField() > > > class Bar(models.Model): > > name = models.CharField() > > foos = models.ManyToManyField(Foo) > > > Then you can, in view code, ask for: > > > >>> Foo.objects.all() > > >>> Bar.objects.all() > > >>> mybar.foos.all() > > >>> myfoo.bar_set.all() > > > And in template, if you have mybar and myfoo into the context, you can > > write: > > {{ mybar }} > > {{ myfoo }} > > {% for foo in mybar.foos.all %} > > {{ foo.name }} > > {% endfor %} > > {% for bar in myfoo.bar_set.all } > > {{ bar.name }} > > {% endfor %} > > > Yours, > > Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---