I'm trying to retrieve a m2m relation from a blog entry. It should give a 
list of entries with the same categories. Below works when I work in the 
shell.

from content.models import Entry
qs = Entry.objects.all()
obj = qs[0]
related = Entry.objects.filter(categories=obj.categories.all())


The obj simulates a single Entry in a template for use in the shell.

I'm trying to put this in a custom template tag, so a list of related 
entries can be shown with a blog entry. I cooked up the following:

            {% load content_tags %}
                {% get_related_entries content.entry from*object.categories.all
* as related_entries %}
                    {% for item in related_entries %}
                            <p><a href="{{ item.get_absolute_url }}">{{ 
item.title }}</a>
                    {% endfor %}

This isn't working though. I'm not sure how to do this, even after 
(re)reading Django-books and documentation. When I don't apply a filter and 
the following in the Node render() works:

context[self.varname] = self.model.objects.all()

Obviously I get a list of all entries, without any filter. I'm pretty sure 
it has to do with the object.categories.all (which is a list of all 
categories) in my template tag and the use of it in the parser/Node. How can 
I achieve this? 

PS:
I didn't include any of my (now many) variants of code I tried on purpose. I 
suspect I'm following an entirely wrong approach and don't want to focus 
attention at wrong code. 

-- 
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/-/4Jzt29ZtGywJ.
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