On Friday, 13 July 2012 13:26:53 UTC-7, bn wrote:
>
> I'm trying to get a template to iterate through and print intermediate 
> model data.  Can you look at this and point out what is wrong?  I've tried 
> to follow the django docs closely:
>
> def category_detail(request, pk):
>     category    = models.Category.objects.select_related().get(pk=pk)
>     entries     = 
> category.entry.order_by('-temp_sort_order').filter(temp_sort_order__gte=0)
>     for entry in entries:
>         assert isinstance(entry, models.Entry)
>
>         ce = models.CategoryEntry2.objects.get(entry=entry, 
> category=category)
>         pprint('1: ' + ce.wiki + str(entry.ce))    # works perfectly
>
>         #foo = entry.ce_set.get(category=category) #'Entry' object has no 
> attribute 'ce_set'
>         #pprint('2: ' + foo.wiki + str(foo.ce))  #'Entry' object has no 
> attribute 'ce_set'
>     for entry in category.ce_set.all:           #'Category' object has no 
> attribute 'ce_set'
>         assert isinstance(entry, models.Entry)
>         pprint('1: ' + entry.wiki)
>
>     return render_to_response('category.html'...)
>
> The Category model has a related_name of 'ce'.:
>
> class Category(models.Model):
>     title           = 
> models.CharField(max_length=1024,null=True,blank=True)
>     entry           = models.ManyToManyField(Entry,null=True,blank=True,
>                                              related_name='ce',
>                                              through='CategoryEntry2',
>                                              )
>
>
>
>

You've set related_name to 'ce', so you should use 'ce'. You've done that 
in the line with the 'works perfectly' comment, so I'm not sure why you 
would think it should be different in the following lines.
--
DR.  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uqv14-gyeTMJ.
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.

Reply via email to