Display arbitrary models

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from django import template

def display_excerpt(object, template_suffix='excerpt'):
    excerpt = object._meta.app_label + "/" + object._meta.module_name + "_" + template_suffix + ".html"
    try:
        t = template.loader.select_template([excerpt, 'display_excerpt.html'])
    except template.TemplateDoesNotExist:
        return str(object)
    c = template.Context({"object": object})
    return t.render(c)

register = template.Library()
register.simple_tag(display_excerpt)

More like this

  1. Pagination/Filtering Alphabetically by zain 5 years, 1 month ago
  2. Class Feeds DRY TemplateTag by gmandx 3 years, 11 months ago
  3. Page numbers with ... like in Digg by Ciantic 5 years ago
  4. Pagination Alphabetically compatible with paginator_class by vascop 2 years ago
  5. Digg-like pagination by SmileyChris 4 years, 11 months ago

Comments

(Forgotten your password?)