Created
September 18, 2013 18:59
-
-
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'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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