December 1st, 2008 posted by Bender Rodríguez
Let's say you have a class like this:
from testcms.contents.models import *
class Contents(UserDict):
def get_contents_list(self):
contents = Contents.objects.all()
for content in contents:
author =
Users.objects.get(userid = content.author_id)
type =
ContentTypes.objects.get(type_id = content.type_id)
relative =
ContentsRelative.objects.filter(content_id =
content.content_id).count()
self[content.id] = {
'content_id' : content.id,
'title' : content.name,
'type' : type.name,
'relative' : relative,
}
return self
And you want to display that Python dictionary at the presentation level with Django templates. Here is what you would do:
{% for content_id, content in contents.items %}
{{ content.title }}
{{ content.type }}
{{ content.relative }}
{% endfor %}
And that's that.
0 Comments, 0 trackbacks (Trackback URL)"The Wire fans no doubt are BSG fans, too, because they seek out kick-ass shows"
Anthony Baker