ContentType template filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# templatetags/helpers.py
from django import template
from django.contrib.contenttypes.models import ContentType

register = template.Library()

@register.filter
def content_type(obj):
    if not obj:
        return False
    return ContentType.objects.get_for_model(obj)

More like this

  1. URL models by diverman 4 years, 6 months ago
  2. improved generic foreign key manager by carljm 5 years, 6 months ago
  3. Generic Model by hakejam 7 years, 1 month ago
  4. ImportObject: Import model *instance* specific code at runtime by guettli 4 years, 8 months ago
  5. Tags & filters for rendering search results by exogen 6 years ago

Comments

(Forgotten your password?)