On Fri, Jun 26, 2009, Brian May <[email protected]> wrote:
>Is it possible to do the same thing with register.simple_tag, and maybe
>takes_context (assuming register.simple_tag supports that)?
What I used in the end was:
@register.inclusion_tag('newslist.html', takes_context=True)
def news_for_this_page(context):
c = context['current_page']
if c: #check it exists
if c.entity_set.all(): # check page belongs to an entity first
e = c.entity_set.all()[0] # first entity will be only one
news = []
for item in e.newsitem_set.all(): # get entity's news items
news.append(item) # add them to the list
return {
'news': news,
}
else:
return "No news is good news"
And that seems to work nicely, for a relatively small bit of work.
Daniele
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---