{% get_related_entries weblog.entry 5 from object.categories as 
related_entries %}
     {% for entry in related_entries %}
          <p><a href="{{ entry.get_absolute_url }}">{{ entry.title }}</a>
     {% endfor %}


class RelatedEntryNode(template.Node):

     def __init__(self, model, number, categories, varname):
         self.model = model
         self.number = int(number)
         self.categories = template.Variable(categories)
         self.varname = varname


>    Ok, so this means that:
>        self.model is a string; literally, in your example, "weblog.entry"

No, self.model shouldn't be a string. It should be the model for Entry in 
app weblog (and I use it like that in other custom template tags that work)

    The templatetag is used when on a blog entry detail page and should give 
a list of related entries (with corresponding categories) .  It comes from 
django.db.models.get_model()  (p117 of Practical Django Projects)

>But that's fine, because your render() method is going to compute some
>value, probably a list of Entry instances in this case, and then it will
>create a new context variable, with the statement;

>context[self.related_entries] = <my_previously_computed_list>

This is where the problem is. I don't get a computed list. It returns 
nothing instead of 1 other related blogentry (in this case)

I'm really stuck now in solving this quite common query:

* a blog entry is shown in a detail page
* this blog entry has categories (m2m relation) Let's assume categories C1 
and C2
* other blog entries have the same categories (also C1 and C2, I'll skip the 
OR relation for now)
* through a custom template tag I want to get the list of Entry instances 
that have categories C1 AND/OR C2 and display them on the detailpage.

* Three database tables are involved in this query
** weblog_entry (which contains the entries)
** category_entry (which contains the categories)
** weblog_entry_categories (which joins the entry with the category)

When displaying the blog entry, Django also references these 3 tables 
(otherwise I wouldn't get the category name in the template.)

I'm going around in circles and am afraid I don't see where the problem 
could be. I reread the books, went through the documentation and searched 
the internet, but am getting nowhere. I'm sure I'm overcomplicating things 
as this should be a quite easy common query to perform.

Maybe you could give a hint or a pointer how you would achieve this thorugh 
a template tag? 

-- 
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/-/VSgdCU_fo5cJ.
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