Skip to content

Instantly share code, notes, and snippets.

@squarepegsys
Created September 18, 2013 18:59
Show Gist options
  • Select an option

  • Save squarepegsys/6613861 to your computer and use it in GitHub Desktop.

Select an option

Save squarepegsys/6613861 to your computer and use it in GitHub Desktop.
This is a Django filter that returns just the base name of the object type. If you have 'book' of type 'book.models.Book', it would return 'Book'.
from django import template
register = template.Library()
@register.filter(name="identify")
def identify(value):
"""
Arguments:
- `value`: some object, probably a model
"""
return str(type(value)).split(".")[-1].replace("'>","")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment